MenuItem.CloneMenu Method (MenuItem)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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


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.

.NET Framework
Available since 1.1
Return to top