Export (0) Print
Expand All

MenuItem.CloneMenu Method

Creates a copy of a MenuItem.

Overload List

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;

Creates a copy of the specified MenuItem.

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

Inherited from Menu.

[Visual Basic] Overloads Protected Sub CloneMenu(Menu)
[C#] protected void CloneMenu(Menu);
[C++] protected: void CloneMenu(Menu*);
[JScript] protected function CloneMenu(Menu);

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, C#, C++] Note   This example shows how to use one of the overloaded versions of CloneMenu. For other examples that might be available, see the individual overload topics.
[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.

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft