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()

Return Value

Type: System.Windows.Forms.MenuItem

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.


.NET Framework
Available since 1.1
Return to top