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)

Initializes a new instance of the class with a specified caption and event handler for the menu item.

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

Parameters

text
The caption for the menu item.
onClick
The EventHandler that handles the EventHandler event 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".

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 to this constructor 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 MenuItem object with a specified caption and an event handler connected to a method that will handle the MenuItem event for the menu item.

[Visual Basic]

Public Sub CreateMyMenuItem()
   ' Create an instance of MenuItem with caption and an event 
handler
   Dim MenuItem1 As MenuItem
   Set MenuItem1 = New MenuItem("&New", New 
System.EventHandler(AddressOf Me.MenuItem1_Click)
End Sub
' This method is an event handler for MenuItem1 to use when 
connecting its 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