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
)
protected void CloneMenu (
	MenuItem itemSrc
)
protected function CloneMenu (
	itemSrc : MenuItem
)
Not applicable.

Parameters

itemSrc

The MenuItem that represents the menu item to copy.

Return Value

A MenuItem that represents the duplicated menu item.

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


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

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft