MenuStrip Constructor

Definition

Initializes a new instance of the MenuStrip class.

public:
 MenuStrip();
public MenuStrip ();
Public Sub New ()

Examples

The following code example demonstrates the MenuStrip constructor. This example is part of a larger example provided for the ToolStripPanel class.

// Create a MenuStrip control with a new window.
MenuStrip ms = new MenuStrip();
ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window");
ToolStripMenuItem windowNewMenu = new ToolStripMenuItem("New", null, new EventHandler(windowNewMenu_Click));
windowMenu.DropDownItems.Add(windowNewMenu);
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowImageMargin = false;
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowCheckMargin = true;

// Assign the ToolStripMenuItem that displays 
// the list of child forms.
ms.MdiWindowListItem = windowMenu;

// Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu);

// Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top;

// The Form.MainMenuStrip property determines the merge target.
this.MainMenuStrip = ms;
' Create a MenuStrip control with a new window.
Dim ms As New MenuStrip()
Dim windowMenu As New ToolStripMenuItem("Window")
Dim windowNewMenu As New ToolStripMenuItem("New", Nothing, New EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True

' Assign the ToolStripMenuItem that displays 
' the list of child forms.
ms.MdiWindowListItem = windowMenu

' Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu)

' Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top

' The Form.MainMenuStrip property determines the merge target.
Me.MainMenuStrip = ms

Remarks

Use this constructor to create a MenuStrip to which you can add ToolStripMenuItem objects.

Applies to