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.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

new : 
        text:string *
        items:MenuItem[] -> MenuItem


Type: System.String

The caption for the menu item.

Type: System.Windows.Forms.MenuItem[]

An array of MenuItem objects that contains the submenu items for this menu item.

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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top