Initializes a new instance of the class with a specified caption, event handler, and associated shorcut key for the menu item.
[Visual Basic] Overloads Public Sub New( _ ByVal text As String, _ ByVal onClick As EventHandler, _ ByVal shortcut As Shortcut _ ) [C#] public MenuItem( string text, EventHandler onClick, Shortcut shortcut ); [C++] public: MenuItem( String* text, EventHandler* onClick, Shortcut shortcut ); [JScript] public function MenuItem( text : String, onClick : EventHandler, shortcut : Shortcut );
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 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.
The following example creates a object with a specified caption, shortcut key, and an event handler connected to a method that will handle the event for the menu item.
[Visual Basic]
Public Sub CreateMyMenuItem() ' Create a MenuItem with caption, shortcut key, and an event handler specified. Dim MenuItem1 As MenuItem Set MenuItem1 = New MenuItem("&New", New System.EventHandler(AddressOf Me.MenuItem1_Click, Shortcut.CtrlL) 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
MenuItem Class | MenuItem Members | System.WinForms Namespace | MenuItem Constructor Overload List