Export (0) Print
Expand All

MenuItem.CloneMenu Method (MenuItem)

Creates a copy of the specified MenuItem.

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

protected void CloneMenu(
	MenuItem itemSrc
)

Parameters

itemSrc
Type: System.Windows.Forms.MenuItem

The MenuItem that represents the menu item to copy.

Call this method to create copies of menu items that you have already created for use in a shortcut menu or another menu structure within your application. This version of CloneMenu allows you to specify a specific MenuItem to copy instead of the menu item that is calling the method. You can use this method to initialize a new MenuItem object with a copy of another MenuItem. When a menu item is cloned, any event handlers specified in the original menu item will continue to function in the cloned version of the menu item. For example, if you created a MenuItem and connected its Click event to an event handler. When the menu item is cloned, the cloned menu item will call the same event handler.

The following code example initializes a new MenuItem with a copy of an existing MenuItem that is used in a MainMenu on a form. The code then adds the cloned MenuItem to a ContextMenu on the form. This example requires that a MenuItem is already created and named menuItem1 and that a ContextMenu control has been created and named contextMenu1.

 public void CloneMyMenu()
 {
    // Clone the existing MenuItem into the new MenuItem.
    MenuItem tempMenuItem = menuItem1.CloneMenu();

    // Assign the cloned MenuItem to the ContextMenu.
    contextMenu1.MenuItems.Add(tempMenuItem);
 }

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft