Menu::CloneMenu Method (Menu^)
.NET Framework (current version)
Namespace:
System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Return to top
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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.
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; }
.NET Framework
Available since 1.1
Available since 1.1
Show: