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

定义

复制作为参数被传递到当前 MenuMenuCopies the Menu that is passed as a parameter to the current Menu.

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

参数

menuSrc
Menu Menu Menu Menu

要复制的 MenuThe Menu to copy.

示例

此示例将创建一个主菜单mainMenu1,其中包含三个菜单FileEdit:、 View和。This example creates a main menu, mainMenu1, with three menu items: File, Edit, and View. 然后,它使用CloneMenu方法将复制mainMenu1mainMenu2中。It then uses the CloneMenu method to copy mainMenu1 into mainMenu2. 然后,将克隆的菜单分配给窗体并显示。The cloned menu is then assigned to the form and displayed. 此程序要求您已经创建了一个名FormForm1的。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

注解

此方法将MenuItem对象(存储在中的Menu menuSrc)的整个列表复制到当前菜单中。This method copies the entire list of MenuItem objects (stored in the Menu passed in to menuSrc) into the current menu. 可以在派生类中使用此方法克隆MenuItem对象。You can use this method in your derived class to clone MenuItem objects. 然后,可以通过派生Menu自的其他类重用这些类, MainMenuContextMenu、和MenuItemThey can then be reused by other classes that derive from Menu, such as MainMenu, ContextMenu, and MenuItem.

适用于

另请参阅