Export (0) Print
Expand All

MainMenu Constructor

.NET Framework 1.1

Initializes a new instance of the MainMenu class.

Overload List

Initializes a new instance of the MainMenu class without any specified menu items.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New()
[C#] public MainMenu();
[C++] public: MainMenu();
[JScript] public function MainMenu();

Initializes a new instance of the MainMenu with a specified set of MenuItem objects.

[Visual Basic] Public Sub New(MenuItem())
[C#] public MainMenu(MenuItem[]);
[C++] public: MainMenu(MenuItem*[]);
[JScript] public function MainMenu(MenuItem[]);

Example

[Visual Basic, C#, C++] The following example creates a MainMenu, and assigns two MenuItem objects to the MainMenu using this version of the constructor. The example then binds the MainMenu to a Form. This example assumes that you have a Form created that is named Form1.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the MainMenu constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub CreateMyMainMenu()
    ' Create two MenuItem objects and assign to array.
    Dim menuItem1 As New MenuItem()
    Dim menuItem2 As New MenuItem()
       
    menuItem1.Text = "&File"
    menuItem2.Text = "&Edit"
       
    ' Create a MainMenu and assign MenuItem objects.
    Dim mainMenu1 As New MainMenu(New MenuItem() {menuItem1, menuItem2})
       
    ' Bind the MainMenu to Form1.
    Menu = mainMenu1
End Sub


[C#] 
public void CreateMyMainMenu()
{
   // Create two MenuItem objects and assign to array.
   MenuItem menuItem1 = new MenuItem();
   MenuItem menuItem2 = new MenuItem();

   menuItem1.Text = "&File";
   menuItem2.Text = "&Edit";

   // Create a MainMenu and assign MenuItem objects.
   MainMenu mainMenu1 = new MainMenu(new MenuItem[] {
         menuItem1,
         menuItem2});
   
   // Bind the MainMenu to Form1.
   Menu = mainMenu1;   
}


[C++] 
public:
 void CreateMyMainMenu()
 {
    // Create two MenuItem objects and assign to array.
    MenuItem* menuItem1 = new MenuItem();
    MenuItem* menuItem2 = new MenuItem();
 
    menuItem1->Text = S"&File";
    menuItem2->Text = S"&Edit";
 
    // Create a MainMenu and assign MenuItem objects.

    MenuItem* temp2 [] = {menuItem1, menuItem2};
    MainMenu* mainMenu1 = new MainMenu(temp2);
    
    // Bind the MainMenu to Form1.
    Menu = mainMenu1;   
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

MainMenu Class | MainMenu Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft