Represents an individual item that is displayed within a MainMenu or ContextMenu. Although ToolStripMenuItem replaces and adds functionality to the control of previous versions, is retained for both backward compatibility and future use if you choose.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Initializes awith a blank caption.
|MenuItem(MenuMerge, Int32, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem())|
Initializes a new instance of theclass with a specified caption for the menu item.
Initializes a new instance of the class with a specified caption and event handler for the Click event of the menu item.
|MenuItem(String, EventHandler, Shortcut)|
Initializes a new instance of the class with a specified caption, event handler, and associated shortcut key for the menu item.
Initializes a new instance of the class with a specified caption and an array of submenu items defined for the menu item.
Gets a value indicating whether the component can raise an event.(Inherited from Component.)
Gets or sets a value indicating whether a check mark appears next to the text of the menu item.
Gets or sets a value indicating whether the menu item is the default menu item.
Gets or sets a value indicating whether the menu item is enabled.
Gets a value representing the window handle for the menu.(Inherited from Menu.)
Gets or sets a value indicating the position of the menu item in its parent menu.
Gets a value indicating whether the menu item contains child menu items.(Overrides Menu.IsParent.)
Gets or sets a value indicating whether the menu item will be populated with a list of the Multiple Document Interface (MDI) child windows that are displayed within the associated form.
Gets a value indicating the Menu.)that is used to display a list of multiple document interface (MDI) child forms.(Inherited from
Gets a value indicating the Windows identifier for this menu item.
Gets a value indicating the collection of Menu.)objects associated with the menu.(Inherited from
Gets or sets a value indicating the relative position of the menu item when it is merged with another.
Gets or sets a value indicating the behavior of this menu item when its menu is merged with another.
Gets a value indicating the mnemonic character that is associated with this menu item.
Gets or sets a value indicating whether the code that you provide draws the menu item or Windows draws the menu item.
Gets a value indicating the menu that contains this menu item.
Gets or sets a value indicating whether the, if checked, displays a radio-button instead of a check mark.
Gets or sets a value indicating the shortcut key associated with the menu item.
Gets or sets a value indicating whether the shortcut key that is associated with the menu item is displayed next to the menu item caption.
Gets or sets user-defined data associated with the control.(Inherited from Menu.)
Gets or sets a value indicating the caption of the menu item.
Gets or sets a value indicating whether the menu item is visible.
Creates a copy of the current.
Creates a copy of the specified.
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)
Disposes of the resources (other than memory) used by the Menu.Dispose(Boolean).).(Overrides
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Gets the Menu.)that contains the value specified. (Inherited from
Returns the position at which a menu item should be inserted into the menu.(Inherited from Menu.)
Serves as the default hash function. (Inherited from Object.)
Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)
Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)
Merges thiswith another and returns the resulting merged .
Merges the Menu.)objects of one menu with the current menu.(Inherited from
Merges another menu item with this menu item.
Raises the Click event.
Raises the DrawItem event.
This API supports the product infrastructure and is not intended to be used directly from your code. Raises the Popup event.
Raises the MeasureItem event.
Raises the Popup event.
Raises the Select event.
Generates a Click event for the , simulating a click by a user.
Raises the Select event for this menu item.
Processes a command key.(Inherited from Menu.)
This API supports the product infrastructure and is not intended to be used directly from your code. Returns a string that represents the Menu.ToString().).(Overrides
Occurs when the menu item is clicked or selected using a shortcut key or access key defined for the menu item.
Occurs when the OwnerDraw property of a menu item is set to true and a request is made to draw the menu item.
Occurs when the menu needs to know the size of a menu item before drawing it.
Occurs before a menu item's list of menu items is displayed.
Occurs when the user places the pointer over a menu item.
The 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 TextBox control, you can use the Checked property to identify which color is currently selected. The Shortcut property can be used to define a keyboard combination that can be pressed to select the menu item.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
For 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 cannot be reused in multiple locations at the same time, such as in a MainMenu and a ContextMenu, you can use the CloneMenu method to create a copy of a for use in another location.objects displayed in a Multiple Document Interface (MDI) application, you can use the
The 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 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.
The following code example creates a menu structure for a form. The example code adds a MainMenu object named mainMenu1 and four objects named menuItem1, menuItem2, menuItem3, and menuItem4.to represent the top-level menu item, adds a submenu item to it for selecting a font size, and then adds two submenu items to that menu item that represent large and small font choices in an application. The example requires that there is a
Public Sub CreateMyMenu() ' Set the caption for the top-level menu item. menuItem1.Text = "Edit" ' Set the caption for the first submenu. menuItem2.Text = "Font Size" ' Set the caption for menuItem2's first submenu. menuItem3.Text = "Small" ' Set the checked property to true since this is the default value. menuItem3.Checked = True ' Define a shortcut key combination for the menu item. menuItem3.Shortcut = Shortcut.CtrlS ' Set the caption of the second sub menu item of menuItem2. menuItem4.Text = "Large" ' Define a shortcut key combination for the menu item. menuItem4.Shortcut = Shortcut.CtrlL ' Set the index of the menu item so it is placed below the first submenu item. menuItem4.Index = 1 ' Add menuItem3 and menuItem4 to menuItem2's list of menu items. menuItem2.MenuItems.Add(menuItem3) menuItem2.MenuItems.Add(menuItem4) ' Add menuItem2 to menuItem1's list of menu items. menuItem1.MenuItems.Add(menuItem2) ' Add menuItem1 to the MainMenu for displaying. mainMenu1.MenuItems.Add(menuItem1) End Sub
Available since 1.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.