Menu.CloneMenu(Menu) Menu.CloneMenu(Menu) Menu.CloneMenu(Menu) Menu.CloneMenu(Menu) Method

Definizione

Copia l'oggetto Menu passato come parametro all'oggetto Menu corrente.Copies the Menu that is passed as a parameter to the current Menu.

protected public:
 void CloneMenu(System::Windows::Forms::Menu ^ menuSrc);
protected internal void CloneMenu (System.Windows.Forms.Menu menuSrc);
member this.CloneMenu : System.Windows.Forms.Menu -> unit
Protected Friend Sub CloneMenu (menuSrc As Menu)

Parametri

menuSrc
Menu Menu Menu Menu

La Menu da copiare.The Menu to copy.

Esempi

Questo esempio viene creato un menu principale mainMenu1, con tre voci di menu: File, Edit, e View.This example creates a main menu, mainMenu1, with three menu items: File, Edit, and View. Quindi, utilizza il CloneMenu metodo per copiare mainMenu1 in mainMenu2.It then uses the CloneMenu method to copy mainMenu1 into mainMenu2. Il menu duplicato viene quindi assegnato al form e visualizzato.The cloned menu is then assigned to the form and displayed. Il programma richiede che sia già stato creato un Form denominato Form1.This program requires that you have already created a Form named Form1.

void CloneMyMainMenu()
{
   // Create the main menu.
   MainMenu^ mainMenu1 = gcnew MainMenu;

   // Create the menu items to add.
   MenuItem^ menuItem1 = gcnew MenuItem;
   MenuItem^ menuItem2 = gcnew MenuItem;
   MenuItem^ menuItem3 = gcnew 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.
   MainMenu^ mainMenu2 = mainMenu1->CloneMenu();

   // Assign mainMenu2 to the form.
   Menu = mainMenu2;
}
private void CloneMyMainMenu()
{
	// Create the main menu.
	MainMenu mainMenu1 = new MainMenu();

	// Create the menu items to add.
	MenuItem menuItem1 = new MenuItem();
	MenuItem menuItem2 = new MenuItem();
	MenuItem menuItem3 = 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.
	MainMenu mainMenu2 = mainMenu1.CloneMenu();
	
	// Assign mainMenu2 to the form.
	Menu = mainMenu2;
}
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

Commenti

Questo metodo copia l'intero elenco di MenuItem oggetti (archiviati nel Menu passato alla menuSrc) nel menu corrente.This method copies the entire list of MenuItem objects (stored in the Menu passed in to menuSrc) into the current menu. È possibile usare questo metodo nella classe derivata da clonare MenuItem oggetti.You can use this method in your derived class to clone MenuItem objects. Possono essere riutilizzati da altre classi che derivano da Menu, ad esempio MainMenu, ContextMenu, e MenuItem.They can then be reused by other classes that derive from Menu, such as MainMenu, ContextMenu, and MenuItem.

Si applica a

Vedi anche