NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

MenuItem Constructor (String, EventHandler, MenuItem[])

Initializes a new instance of the class with a specified caption, event handler, and an array of submenu items defined for the menu item.

[Visual Basic]
Overloads Public Sub New( _
   ByVal text As String, _
   ByVal onClick As EventHandler, _
   ByVal items() As MenuItem _
)
[C#]
public MenuItem(
   string text,
   EventHandler onClick,
   MenuItem[] items
);
[C++]
public: MenuItem(
   String* text,
   EventHandler* onClick,
   MenuItem* items[]
);
[JScript]
public function MenuItem(
   text : String,
   onClick : EventHandler,
   items : MenuItem[]
);

Parameters

text
The caption for the menu item.
onClick
The EventHandler that handles the EventHandler event for this menu item.
items
An array of type MenuItem that contains the submenu items for this menu item.

Remarks

When you specify a caption for your menu item with the text parameter, you can also specify an accelerator key by placing an '&' before the character to be used as the accelerator key. For example, to specify the "F" in "File" as an accelerator key, you would specify the caption for the menu item as "&File".

The items parameter allows you to assign an array of 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. Since each menu item can have any number of menu items assigned to it, you can very easily create complete menu structures.

In addition, you can use this constructor to create a and have it connected to an event handler in your code that will process the click of the menu item. The EventHandler that you pass into this contructor should be configured to call an event handler that can handle the System.Click event. For more information on handling events see TBD.

Example [Visual Basic]

The following example creates a 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.

[Visual Basic]

Public Sub CreateMyMenuItem()
   ' Sub menu item array.
   Dim SubMenus(3) as MenuItem
   ' Create three menu items to add to the submenu item array.
   Dim SubMenuItem1, SubMenuItem2, SubMenuItem3 as MenuItem
   Set SubMenuItem1 = New MenuItem ("Red")
   Set SubMenuItem2 = New MenuItem ("Blue")
   Set SubMenuItem3 = New MenuItem ("Green")
   ' Add the submenu items to the array.
   Set SubMenus(1) = SubMenuItem1
   Set SubMenus(2) = SubMenuItem2
   Set SubMenus(3) = SubMenuItem3
   ' Create an instance of a MenuItem with caption, an event 
handler, and an array of submenu items specified.
   Dim MenuItem1 As MenuItem
   Set MenuItem1 = New MenuItem("&Colors", New 
System.EventHandler(AddressOf Me.MenuItem1_Click, SubMenus)
End Sub
' The following method is an event handler for MenuItem1 to use 
when connecting the event handler.
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal 
e as System.EventArgs)
   ' Code goes here that handles the Click event.
End Sub

See Also

MenuItem Class | MenuItem Members | System.WinForms Namespace | MenuItem Constructor Overload List