Partager via


How to: Disable ToolStripMenuItems

You can limit or broaden the commands a user may make by enabling and disabling menu items in response to user activities. Menu items are enabled by default when they are created, but this can be adjusted through the Enabled property. You can manipulate this property at design time in the Properties window or programmatically by setting it in code.

To disable a menu item programmatically

  • Within the method where you set the properties of the menu item, add code to set the Enabled property to false.

    MenuItem1.Enabled = False
    
    menuItem1.Enabled = false;
    
    menuItem1.set_Enabled(false);
    
    menuItem1->Enabled = false;
    
    NoteTip

    Disabling the first or top-level menu item in a menu disables all the menu items contained within the menu. Likewise, disabling a menu item that has submenu items disables the submenu items. If all the commands on a given menu are unavailable to the user, it is considered good programming practice to both hide and disable the entire menu, as this presents a clean user interface. You should both hide and disable the menu, as hiding alone does not prevent access to a menu command via a shortcut key. Set the Visible property of a top-level menu item to false to hide the entire menu.

See Also

Tasks

How to: Hide ToolStripMenuItems

Reference

MenuStrip Control Overview (Windows Forms)
MenuStrip
ToolStripMenuItem