Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MenuItem.MergeMenu Method

Merges this MenuItem with another MenuItem.

Overload List

Merges this MenuItem with another MenuItem and returns the resulting merged MenuItem.

[Visual Basic] Overloads Public Overridable Function MergeMenu() As MenuItem
[C#] public virtual MenuItem MergeMenu();
[C++] public: virtual MenuItem* MergeMenu();
[JScript] public function MergeMenu() : MenuItem;

Merges another menu item with this menu item.

[Visual Basic] Overloads Public Sub MergeMenu(MenuItem)
[C#] public void MergeMenu(MenuItem);
[C++] public: void MergeMenu(MenuItem*);
[JScript] public function MergeMenu(MenuItem);

Inherited from Menu.

[Visual Basic] Overloads Public Overridable Sub MergeMenu(Menu)
[C#] public virtual void MergeMenu(Menu);
[C++] public: virtual void MergeMenu(Menu*);
[JScript] public function MergeMenu(Menu);

Example

[Visual Basic, C#, C++] The following 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 assumes 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.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of MergeMenu. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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


[C#] 
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);
}


[C++] 
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);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace

Show:
© 2015 Microsoft