This documentation is archived and is not being maintained.

MainMenu Constructor (MenuItem[])

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public MainMenu(
	MenuItem[] items
)

Parameters

items
Type: System.Windows.Forms.MenuItem[]
An array of MenuItem objects that will be added to the MainMenu.

You can use this constructor to assign an array of MenuItem objects to the MainMenu at the time of its creation. After the MainMenu has been created you can add additional MenuItem objects to the MainMenu using the Add method of the MenuItems property.

The following code 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 requires that you have a Form created that is named Form1.


 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;   
 }



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: