Export (0) Print
Expand All

Menu.MenuItemCollection.Add Method (String, MenuItem[])

Adds a new MenuItem to the end of this menu with the specified caption, Click event handler, and items.

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

public virtual MenuItem Add(
	string caption,
	MenuItem[] items
)

Parameters

caption
Type: System.String
The caption of the menu item.
items
Type: System.Windows.Forms.MenuItem[]
An array of MenuItem objects that this MenuItem will contain.

Return Value

Type: System.Windows.Forms.MenuItem
A MenuItem that represents the menu item being added to the collection.

A MenuItem can only be contained in one menu at a time, and cannot be added more than once to the same menu. To reuse a MenuItem in more than one menu, use the CloneMenu method of the MenuItem class. To remove a MenuItem that you have previously added, use the Remove method.

This version of the Add method allows you to specify a caption for the menu item and a delegate that will handle its Click event. You can use this version of the Add method if your application already has an event handler to handle the Click event. This version of the method also allows you to specify an array of previously created MenuItem objects that you want to add to the collection. You can use this feature to reuse existing MenuItem objects that have been cloned using the CloneMenu method. If the items parameter is not empty or null, the MenuItem being added to the collection will contain submenu items.

NoteNote

The Click event is not raised for a MenuItem that contains submenu items.

.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.

Community Additions

ADD
Show:
© 2014 Microsoft