ToolStripMenuItem Constructor (String, Image, EventHandler)

 

Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that does the specified action when the ToolStripMenuItem is clicked.

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

public ToolStripMenuItem(
	string text,
	Image image,
	EventHandler onClick
)

Parameters

text
Type: System.String

The text to display on the menu item.

image
Type: System.Drawing.Image

The Image to display on the control.

onClick
Type: System.EventHandler

An event handler that raises the Click event when the control is clicked.

Use the ToolStripMenuItem to create a ToolStripMenuItem that displays both text and an image and that does the specified action when the ToolStripMenuItem is clicked.

The following code example demonstrates a use of the ToolStripMenuItem constructor.

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

.NET Framework
Available since 2.0
Return to top
Show: