MenuItem Constructor (String, MenuItem())
Initializes a new instance of the class with a specified caption and an array of submenu items defined for the menu item.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". You can use this feature to provide keyboard navigation for your menus.
Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.
The items parameter enables you to assign an array of menu items to define a submenu of this menu item. Each item in the array can also have an array of menu items assigned to it. This enables you to create complete menu structures and assign them to the constructor for the menu item.
For more information on handling events, see Handling and Raising Events.
The following code example creates an object with a specified caption, an event handler connected to a method that will handle the event each menu item in an array of submenu items.
Public Sub CreateMyMenuItem() ' submenu item array. Dim subMenus(3) As MenuItem ' Create three menu items to add to the submenu item array. Dim subMenuItem1 As New MenuItem("Red") Dim subMenuItem2 As New MenuItem("Blue") Dim subMenuItem3 As New MenuItem("Green") ' Add the submenu items to the array. subMenus(0) = subMenuItem1 subMenus(1) = subMenuItem2 subMenus(2) = subMenuItem3 ' Create an instance of a MenuItem with caption and an array of submenu ' items specified. Dim MenuItem1 As New MenuItem("&Colors", subMenus) End Sub
Available since 1.1