Export (0) Print
Expand All

MenuItem.CloneMenu Method ()

Creates a copy of the current MenuItem.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual MenuItem CloneMenu ()
public MenuItem CloneMenu ()
public function CloneMenu () : MenuItem
Not applicable.

Return Value

A MenuItem that represents the duplicated menu item.

MenuItem objects cannot be used in more than one place unless you obtain a copy of the MenuItem. You can call this method to create a copy of this menu item for use in a ContextMenu, MainMenu, or other MenuItem within your application. 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 clones a MenuItem and displays it in a ContextMenu. The example requires that a MenuItem exists in a MainMenu on a form with the name of menuItem1 and that a ContextMenu object named contextMenu1 also exists on the form.

public void CloneMyMenu()
{
   // Clone the menu item and add it to the collection for the shortcut menu.
   contextMenu1.MenuItems.Add(menuItem1.CloneMenu());
   
}


public void CloneMyMenu()
{
    // Clone the menu item and add it to the 
    // collection for the shortcut menu.
    contextMenu1.get_MenuItems().Add(menuItem1.CloneMenu());
} //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:
© 2014 Microsoft