Export (0) Print
Expand All

MenuItem.CloneMenu Method (MenuItem)

.NET Framework 1.1

Creates a copy of the specified MenuItem.

[Visual Basic]
Overloads Protected Sub CloneMenu( _
   ByVal itemSrc As MenuItem _
)
[C#]
protected void CloneMenu(
 MenuItem itemSrc
);
[C++]
protected: void CloneMenu(
 MenuItem* itemSrc
);
[JScript]
protected function CloneMenu(
   itemSrc : MenuItem
);

Parameters

itemSrc
The MenuItem that represents the menu item to copy.

Return Value

A MenuItem that represents the duplicated menu item.

Remarks

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.

Example

[Visual Basic, C#, C++] The following 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 assumes that a MenuItem is already created and named menuItem1 and that a ContextMenu control has been created and named contextMenu1.

[Visual Basic] 
Public Sub CloneMyMenu()
    ' Clone the existing MenuItem into the new MenuItem.
    Dim tempMenuItem As MenuItem = menuItem1.CloneMenu()
       
    ' Assign the cloned MenuItem to the ContextMenu.
    contextMenu1.MenuItems.Add(tempMenuItem)
End Sub


[C#] 
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);
}


[C++] 
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);
 }

[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:
© 2015 Microsoft