Menu Items
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Menus usually contain multiple "items". Each item is identified by a short text string, such as "File" or "Exit". When you see a menu in an application such as notepad, there are some items that are always visible. These are called "top-level" items, which can be selected with either the mouse or keyboard shortcuts (if available). When you select a "top-level" item, usually a sub-menu or "drop-down menu" containing more items is displayed.
Each menu item is created using the ToolStripMenuItem class.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem (abstract)
System.Windows.Forms.ToolStripDropDownItem
System.Windows.Forms.ToolStripMenuItem
ToolStripMenuItem
The ToolStripMenuItem class represents a menu within a MenuStrip or ContextMenuStrip. It can also represent a submenu of another ToolStripMenuItem object. ToolStripMenuItem objects are viewed by the user, whereas a MenuStrip or ContextMenuStrip object simply establishes a container where menu items appear.
Useful properties
-
Checked- Gets or sets whether a checkmark appears next to the text of the menu item. -
CheckState- Gets or sets a three-state value for the menu item, based on theCheckStateenumeration. This is similar toChecked, but allows an indeterminate setting when the checked or unchecked state cannot be determined. -
Enabled(overridden fromToolStripItem) - Gets or sets whether the menu item is enabled. A disabled menu is displayed in a grayed-out state and cannot be selected or display any child menu items. -
Overflow(overridden fromToolStripItem) - Gets or sets how the menu item interacts with an overflow button, based on theToolStripItemOverflowenumeration. -
ShortcutKeyDisplayStringGets or sets the string to display as the shortcut for the menu. If this is blank, the actual shortcut key setting is shown. -
ShortcutKeys- Gets or sets the shortcut keys for this menu item, using theKeysenumeration values. -
ShowShortcutKeys- Gets or sets whether to display theShortcutKeyssetting when displaying the menu.