Export (0) Print
Expand All
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

MenuMerge Enumeration

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

[Visual Basic]
<Serializable>
Public Enum MenuMerge
[C#]
[Serializable]
public enum MenuMerge
[C++]
[Serializable]
__value public enum MenuMerge
[JScript]
public
   Serializable
enum MenuMerge

Remarks

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

Members

Member name Description
Add The MenuItem is added to the collection of existing MenuItem objects in a merged menu.
MergeItems All submenu items of this MenuItem are merged with those of existing MenuItem objects at the same position in a merged menu.
Remove The MenuItem is not included in a merged menu.
Replace The MenuItem replaces an existing MenuItem at the same position in a merged 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] 
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.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

System.Windows.Forms Namespace

Show:
© 2014 Microsoft. All rights reserved.