This documentation is archived and is not being maintained.

MenuItem.CloneMenu Method ()

.NET Framework 1.1

Creates a copy of the current MenuItem.

[Visual Basic]
Overloads Public Overridable Function CloneMenu() As MenuItem
[C#]
public virtual MenuItem CloneMenu();
[C++]
public: virtual MenuItem* CloneMenu();
[JScript]
public function CloneMenu() : MenuItem;

Return Value

A MenuItem that represents the duplicated menu item.

Remarks

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.

Example

[Visual Basic, C#, C++] The following example clones a MenuItem and displays it in a ContextMenu. The example assumes that a MenuItem exists in a MainMenu object on a form with the name of menuItem1 and a that a ContextMenu object named contextMenu1 also exists on the form.

[Visual Basic] 
Public Sub CloneMyMenu()

    ' Clone the menu item and add it to the collection for the context menu.
    contextMenu1.MenuItems.Add(menuItem1.CloneMenu())
    
End Sub


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


[C++] 
public:
 void CloneMyMenu()
 {
    // Clone the menu item and add it to the collection for the context menu.
    contextMenu1->MenuItems->Add(menuItem1->CloneMenu());
    
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace | MenuItem.CloneMenu Overload List

Show: