This documentation is archived and is not being maintained.

Menu.CloneMenu Method

Copies the Menu that is passed as a parameter to the current Menu.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Protected Friend Sub CloneMenu ( _
	menuSrc As Menu _
)
'Usage
Dim menuSrc As Menu 

Me.CloneMenu(menuSrc)

Parameters

menuSrc
Type: System.Windows.Forms.Menu

The Menu to copy.

This method copies the entire list of MenuItem objects (stored in the Menu passed in to menuSrc) into the current menu. You can use this method in your derived class to clone MenuItem objects. They can then be reused by other classes that derive from Menu, such as MainMenu, ContextMenu, and MenuItem.

This example creates a main menu, mainMenu1, with three menu items: File, Edit, and View. It then uses the CloneMenu method to copy mainMenu1 into mainMenu2. The cloned menu is then assigned to the form and displayed. This program requires that you have already created a Form named Form1.

Private Sub CloneMyMainMenu()
   ' Create the main menu. 
   Dim mainMenu1 As New MainMenu()

   ' Create the menu items to add. 
   Dim menuItem1 As New MenuItem()
   Dim menuItem2 As New MenuItem()
   Dim menuItem3 As New MenuItem()

   ' Set the caption for the menu items.
   menuItem1.Text = "File"
   menuItem2.Text = "Edit"
   menuItem3.Text = "View" 

   ' Add the menu item to mainMenu1.
   mainMenu1.MenuItems.Add(menuItem1)
   mainMenu1.MenuItems.Add(menuItem2)
   mainMenu1.MenuItems.Add(menuItem3)

   ' Clone the mainMenu1 and name it mainMenu2. 
   Dim mainMenu2 As MainMenu = mainMenu1.CloneMenu()

   ' Assign mainMenu2 to the form.
   Menu = mainMenu2
End Sub 'CloneMyMainMenu

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: