Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-disable-toolstripmenuitems.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.3 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Disable ToolStripMenuItems 03/30/2017
csharp
vb
cpp
ToolStripMenuItems [Windows Forms], enabling
ToolStripMenuItems [Windows Forms], disabling
menu items [Windows Forms], disabling
disabling menu items
menu items [Windows Forms], enabling
menus [Windows Forms], disabling menu items
bcc1da84-50fd-41d2-8475-103b581d5654

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 xref:System.Windows.Forms.ToolStripMenuItem.Enabled%2A 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 xref:System.Windows.Forms.ToolStripMenuItem.Enabled%2A property to false.

    MenuItem1.Enabled = False  
    
    menuItem1.Enabled = false;  
    
    menuItem1->Enabled = false;  
    

    Tip

    Disabling the first or top-level menu item in a menu hides all the menu items contained within the menu, but does not disable them. Likewise, disabling a menu item that has submenu items hides the submenu items, but does not disable them. 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 hide and disable the menu, and disable every item and submenu item in the menu, because hiding alone does not prevent access to a menu command via a shortcut key. Set the xref:System.Windows.Forms.ToolStripItem.Visible%2A property of a top-level menu item to false to hide the entire menu.

See also