Export (0) Print
Expand All

MenuItem.Enabled Property

Gets or sets a value indicating whether the menu item is enabled.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Property Enabled As Boolean

Property Value

Type: System.Boolean
true if the menu item is enabled; otherwise, false. The default is true.

A MenuItem that is disabled is displayed in a gray color to indicate its state. When a parent menu item is disabled, all submenu items are not displayed.

The following code example demonstrates how to use the Popup event to determine whether MenuItem objects that provide support for cut, copy, and delete operations are enabled before the menu they are displayed in is shown. The example determines if textBox1, a TextBox control on the form, is enabled, has input focus, and has text selected before enabling the MenuItem objects. This example requires that three MenuItem objects are created named menuCut, menuCopy, and menuDelete have been created.


Private Sub PopupMyMenu(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuEdit.Popup
   If textBox1.Enabled = False OrElse textBox1.Focused = False OrElse textBox1.SelectedText.Length = 0 Then
      menuCut.Enabled = False
      menuCopy.Enabled = False
      menuDelete.Enabled = False
   Else
      menuCut.Enabled = True
      menuCopy.Enabled = True
      menuDelete.Enabled = True
   End If
End Sub


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft