MenuItem.Enabled Property

Definition

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

C#
public bool Enabled { get; set; }

Property Value

true if the menu item is enabled; otherwise, false. The default is true.

Examples

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.

C#
private void PopupMyMenu(object sender, System.EventArgs e)
{
   if (!textBox1.Enabled || !textBox1.Focused ||
      textBox1.SelectedText.Length == 0)
   {
      menuCut.Enabled = false;
      menuCopy.Enabled = false;
      menuDelete.Enabled = false;
   }
   else
   {
      menuCut.Enabled = true;
      menuCopy.Enabled = true;
      menuDelete.Enabled = true;
   }
}

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10