MenuItem.MergeMenu 方法

定义

将此 MenuItem 与另一个 MenuItem 合并。Merges this MenuItem with another MenuItem.

重载

MergeMenu(MenuItem)

将另一菜单项与该菜单项合并。Merges another menu item with this menu item.

MergeMenu()

将此 MenuItem 与另一个 MenuItem 合并并返回合并后的 MenuItemMerges this MenuItem with another MenuItem and returns the resulting merged MenuItem.

MergeMenu(MenuItem)

将另一菜单项与该菜单项合并。Merges another menu item with this menu item.

public:
 void MergeMenu(System::Windows::Forms::MenuItem ^ itemSrc);
public void MergeMenu (System.Windows.Forms.MenuItem itemSrc);
override this.MergeMenu : System.Windows.Forms.MenuItem -> unit
Public Sub MergeMenu (itemSrc As MenuItem)

参数

itemSrc
MenuItem

指定要与该菜单项合并的菜单项的 MenuItemA MenuItem that specifies the menu item to merge with this one.

示例

下面的代码示例使用此版本MergeMenu的方法创建的副本MenuItem ,并将其与另一个合并。The following code example uses this version of the MergeMenu method to create a copy of a MenuItem and merge it with another. 合并MenuItem后将添加ContextMenu到控件中。The merged MenuItem is then added to a ContextMenu control. 此示例要求menuItem1有两个名menuItem2为的菜单项,其中包含其中的子菜单项, contextMenu1并将一个名为的ContextMenu菜单项显示菜单项。This example requires that there are two menu items called menuItem1 and menuItem2 that contain submenu items within them and a ContextMenu named contextMenu1 to display the menu items. menuItem1menuItem2中包含不同的菜单项。menuItem1 and menuItem2 have different menu items contained within them. 调用MergeMenu完成后,将创建一个合并菜单。After the call to MergeMenu is made, a consolidated menu is created.

private:
   void MergeMyMenus()
   {
      // Set the merge type to merge the items from both top menu items.
      menuItem1->MergeType = MenuMerge::MergeItems;
      menuItem2->MergeType = MenuMerge::MergeItems;
      // Create a copy of my menu item.
      MenuItem^ tempMenuItem = gcnew MenuItem;
      // Create a copy of menuItem1 before doing the merge.
      tempMenuItem = menuItem1->CloneMenu();
      // Merge menuItem1's copy with a clone of menuItem2
      tempMenuItem->MergeMenu( menuItem2->CloneMenu() );
      
      // Add the merged menu to the ContextMenu control.
      contextMenu1->MenuItems->Add( tempMenuItem );
   }
private void MergeMyMenus()
{
   // Set the merge type to merge the items from both top menu items.
   menuItem1.MergeType = MenuMerge.MergeItems;
   menuItem2.MergeType = MenuMerge.MergeItems;
   // Create a copy of my menu item.
   MenuItem tempMenuItem = new MenuItem();
   // Create a copy of menuItem1 before doing the merge.
   tempMenuItem = menuItem1.CloneMenu();
   // Merge menuItem1's copy with a clone of menuItem2
   tempMenuItem.MergeMenu(menuItem2.CloneMenu());

   // Add the merged menu to the ContextMenu control.
   contextMenu1.MenuItems.Add(tempMenuItem);
}

Private Sub MergeMyMenus()
    ' Set the merge type to merge the items from both top menu items.
    menuItem1.MergeType = MenuMerge.MergeItems
    menuItem2.MergeType = MenuMerge.MergeItems
    ' Create a copy of my menu item.
    Dim tempMenuItem As New MenuItem()
    ' Create a copy of menuItem1 before doing the merge.
    tempMenuItem = menuItem1.CloneMenu()
    ' Merge menuItem1's copy with a clone of menuItem2
    tempMenuItem.MergeMenu(menuItem2.CloneMenu())
       
    ' Add the merged menu to the ContextMenu control.
    contextMenu1.MenuItems.Add(tempMenuItem)
End Sub

注解

根据菜单项的MergeTypeMergeOrder属性的值合并菜单项。Menu items are merged according to the value of the menu item's MergeType and MergeOrder properties. 此版本的MergeMenu方法使您能够将两个MenuItem对象(及其子菜单)合并为一个菜单。This version of the MergeMenu method enables you to merge two MenuItem objects (and their submenus) into a single menu. 当多文档界面(MDI)父窗体和子级都具有菜单时,将自动处理菜单合并。Menu merging is handled automatically when a Multiple Document Interface (MDI) parent form and a child both have menus. 您可以使用此版本的方法将MenuItem MainMenu控件中的两个对象(及其子菜单项)合并为中ContextMenu的单个菜单。You can use this version of the method to merge two MenuItem objects (and their submenu items) located in a MainMenu control into a single menu within a ContextMenu. 例如,你可以调用此版本的MergeMenu方法将文件的菜单项和编辑菜单合并为单个MenuItem ,然后可以将其添加ContextMenu到中并由其显示。For example, you can call this version of the MergeMenu method to merge the menu items of a File and Edit menu into a single MenuItem that can then be added to and displayed by a ContextMenu.

MergeMenu()

将此 MenuItem 与另一个 MenuItem 合并并返回合并后的 MenuItemMerges this MenuItem with another MenuItem and returns the resulting merged MenuItem.

public:
 virtual System::Windows::Forms::MenuItem ^ MergeMenu();
public virtual System.Windows.Forms.MenuItem MergeMenu ();
override this.MergeMenu : unit -> System.Windows.Forms.MenuItem
Public Overridable Function MergeMenu () As MenuItem

返回

表示合并菜单项的 MenuItemA MenuItem that represents the merged menu item.

注解

当你调用此版本的MergeMenu时, MenuItem返回的是当前菜单项的副本,可与其他菜单项合并,而不会影响当前项的功能。When you call this version of MergeMenu, the MenuItem returned is a copy of the current menu item that can be merged with another menu item without affecting the functionality of the current item. 此版本的MergeMenu方法类似于CloneMenu调用不包含参数的方法。This version of the MergeMenu method is similar to calling the CloneMenu method that contains no parameters.

适用于