편집

다음을 통해 공유


MenuItem.MergeMenu Method

Definition

Merges this MenuItem with another MenuItem.

Overloads

MergeMenu(MenuItem)

Merges another menu item with this menu item.

MergeMenu()

Merges 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)

Parameters

itemSrc
MenuItem

A MenuItem that specifies the menu item to merge with this one.

Examples

The following code example uses this version of the MergeMenu method to create a copy of a MenuItem and merge it with another. The merged MenuItem is then added to a ContextMenu control. 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. menuItem1 and menuItem2 have different menu items contained within them. 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

Remarks

Menu items are merged according to the value of the menu item's MergeType and MergeOrder properties. This version of the MergeMenu method enables you to merge two MenuItem objects (and their submenus) into a single menu. Menu merging is handled automatically when a Multiple Document Interface (MDI) parent form and a child both have menus. 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. 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.

Applies to

MergeMenu()

Merges 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

Returns

A MenuItem that represents the merged menu item.

Remarks

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. This version of the MergeMenu method is similar to calling the CloneMenu method that contains no parameters.

Applies to