System.Windows.Forms.MenuItem Class

Represents an individual item that is displayed within a System.Windows.Forms.MainMenu or System.Windows.Forms.ContextMenu. Although System.Windows.Forms.ToolStripMenuItem replaces and adds functionality to the System.Windows.Forms.MenuItem control of previous versions, System.Windows.Forms.MenuItem is retained for both backward compatibility and future use if you choose.

See Also: MenuItem Members

Syntax

[System.ComponentModel.ToolboxItem(false)]
[System.ComponentModel.DesignTimeVisible(false)]
[System.ComponentModel.DefaultEvent("Click")]
[System.ComponentModel.DefaultProperty("Text")]
public class MenuItem : Menu

Remarks

In order for a System.Windows.Forms.MenuItem to be displayed, you must add it to a System.Windows.Forms.MainMenu or System.Windows.Forms.ContextMenu. To create submenus, you can add System.Windows.Forms.MenuItem objects to the Menu.MenuItems property of the parent System.Windows.Forms.MenuItem.

The System.Windows.Forms.MenuItem class provides properties that enable you to configure the appearance and functionality of a menu item. To display a check mark next to a menu item, use the MenuItem.Checked property. You can use this feature to identify a menu item that is selected in a list of mutually exclusive menu items. For example, if you have a set of menu items for setting the color of text in a System.Windows.Forms.TextBox control, you can use the MenuItem.Checked property to identify which color is currently selected. The MenuItem.Shortcut property can be used to define a keyboard combination that can be pressed to select the menu item.

For System.Windows.Forms.MenuItem objects displayed in a Multiple Document Interface (MDI) application, you can use the MenuItem.MergeMenu method to merge the menus of an MDI parent for with that of its child forms to create a consolidated menu structure. Because a System.Windows.Forms.MenuItem cannot be reused in multiple locations at the same time, such as in a System.Windows.Forms.MainMenu and a System.Windows.Forms.ContextMenu, you can use the MenuItem.CloneMenu method to create a copy of a System.Windows.Forms.MenuItem for use in another location.

The MenuItem.Popup event enables you to perform tasks before a menu is displayed. For example, you can create an event handler for this event to display or hide menu items based on the state of your code. The MenuItem.Select event enables you to perform tasks such as providing detailed help for your application's menu items when the user places the mouse pointer over a menu item.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0