MainMenu Constructor ()
Collapse the table of content
Expand the table of content

MainMenu.MainMenu() Constructor

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public MainMenu ()
public MainMenu ()
public function MainMenu ()
Not applicable.

This version of the constructor creates a MainMenu without any specified MenuItem objects. To add menu items to the control use the other version of this constructor that accepts an array of MenuItem objects as its parameter or use the Add method of the MenuItems property.

The following code example creates a MainMenu, assigns two MenuItem objects to the MainMenu and binds it to a form. This example requires that you have a Form created that is named Form1.

public void CreateMyMainMenu()
{
   // Create an empty MainMenu.
   MainMenu mainMenu1 = new MainMenu();

   MenuItem menuItem1 = new MenuItem();
   MenuItem menuItem2 = new MenuItem();

   menuItem1.Text = "File";
   menuItem2.Text = "Edit";
   // Add two MenuItem objects to the MainMenu.
   mainMenu1.MenuItems.Add(menuItem1);
   mainMenu1.MenuItems.Add(menuItem2);
   
   // Bind the MainMenu to Form1.
   Menu = mainMenu1;   
}


public void CreateMyMainMenu()
{
    // Create an empty MainMenu.
    MainMenu mainMenu1 = new MainMenu();
    MenuItem menuItem1 = new MenuItem();
    MenuItem menuItem2 = new MenuItem();

    menuItem1.set_Text("File");
    menuItem2.set_Text("Edit");

    // Add two MenuItem objects to the MainMenu.
    mainMenu1.get_MenuItems().Add(menuItem1);
    mainMenu1.get_MenuItems().Add(menuItem2);

    // Bind the MainMenu to Form1.
    set_Menu(mainMenu1);
} //CreateMyMainMenu

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft