Initializes a new instance of the TBD class.
Initializes a MenuItem with a blank caption.
[Visual Basic] Overloads Public Sub New()
[C#] public MenuItem();
[C++] public: MenuItem();
[JScript] public function MenuItem();
Initializes a new instance of the TBD class with a specified caption for the menu item.
[Visual Basic] Overloads Public Sub New(String)
[C#] public MenuItem(String);
[C++] public: MenuItem(String*);
[JScript] public function MenuItem(String);
Initializes a new instance of the class with a specified caption and event handler for the menu item.
[Visual Basic] Overloads Public Sub New(String, EventHandler)
[C#] public MenuItem(String, EventHandler);
[C++] public: MenuItem(String*, EventHandler);
[JScript] public function MenuItem(String, EventHandler);
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(String, EventHandler, Shortcut)
[C#] public MenuItem(String, EventHandler, Shortcut);
[C++] public: MenuItem(String*, EventHandler, Shortcut);
[JScript] public function MenuItem(String, EventHandler, Shortcut);
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(String, EventHandler, MenuItem())
[C#] public MenuItem(String, EventHandler, MenuItem[]);
[C++] public: MenuItem(String*, EventHandler, MenuItem[]);
[JScript] public function MenuItem(String, EventHandler, MenuItem[]);
Initializes a new instance of the class with a specified caption, defined event-handlers for the System.MenuItem.Click, System.MenuItem.Select and System.WinForms.MenuItem.Popup events, a shortcut key, a merge type, and order specified for the menu item.
[Visual Basic] Overloads Public Sub New(MenuMerge, Integer, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem())
[C#] public MenuItem(MenuMerge, int, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem[]);
[C++] public: MenuItem(MenuMerge, int, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem[]);
[JScript] public function MenuItem(MenuMerge, int, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem[]);
The following example creates a menu item that has a caption and shortcut key. The menu item also has event handlers defined for the System.WinForms.MenuItem.Popup, System.WinForms.MenuItem.Click, and System.WinForms.MenuItem.Select events. If this menu item is merged, it will add the menu item to the menu with the merge order of zero.
Note This example shows how to use one of the overloaded version of the MenuItem constructor. For other examples that may be available, see the individual overload topics.
[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, shortcut key, a Click, Popup, and Select event handler, menu merge type and order, and an array of submenu items specified. Dim MenuItem1 As MenuItem Set MenuItem1 = New MenuItem(MenuMerge.Add, 0, "&Colors", _ New System.EventHandler(AdressOf Me.MenuItem1_Click), _ New System.EventHandler(AdressOf Me.MenuItem1_Popup), _ New System.EventHandler(AdressOf Me.MenuItem1_Select), SubMenus) End Sub ' The following method is an event handler for MenuItem1 to use when connecting the Click event. Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) ' Code goes here that handles the Click event. End Sub ' The following method is an event handler for MenuItem1 to use when connecting the Popup event. Private Sub MenuItem1_Popup(ByVal sender As System.Object, ByVal e as System.EventArgs) ' Code goes here that handles the Click event. End Sub ' The following method is an event handler for MenuItem1 to use when connecting the Select event Private Sub MenuItem1_Select(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