Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

MenuMerge Enumeration

Specifies the behavior of a MenuItem when it is merged with items in another menu.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public enum MenuMerge
public enum MenuMerge
public enum MenuMerge
 Member nameDescription
AddThe MenuItem is added to the collection of existing MenuItem objects in a merged menu. 
MergeItemsAll submenu items of this MenuItem are merged with those of existing MenuItem objects at the same position in a merged menu. 
RemoveThe MenuItem is not included in a merged menu. 
ReplaceThe MenuItem replaces an existing MenuItem at the same position in a merged menu. 

Use the members of this enumeration to set the value of the MergeType property of the MenuItem.

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.

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 void MergeMyMenus()
{
    // Set the merge type to merge the items from both top menu items.
    menuItem1.set_MergeType(MenuMerge.MergeItems);
    menuItem2.set_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.get_MenuItems().Add(tempMenuItem);
} //MergeMyMenus

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.