Export (0) Print
Expand All

MenuItem.MergeOrder Property

Gets or sets a value indicating the relative position of the menu item when it is merged with another.

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

public int MergeOrder { get; set; }
/** @property */
public int get_MergeOrder ()

/** @property */
public void set_MergeOrder (int value)

public function get MergeOrder () : int

public function set MergeOrder (value : int)

Not applicable.

Property Value

A zero-based index representing the merge order position for this menu item. The default is 0.

The merge order of a menu item specifies the relative position that this menu item will take if the menu structure that the MenuItem is contained in is merged with another.

The following code example demonstrates using the MergeOrder property to control the way a merged menu is displayed. This is a complete example, ready to run once you add it to your project.

// The following code example demonstrates using the MenuItem 
// Merge-Order property to control the way a merged menu is displayed.



using System.Windows.Forms;

public class Form1:
	System.Windows.Forms.Form

	//Declare a MainMenu object and its items.
{
	internal System.Windows.Forms.MainMenu mainMenu1;
	internal System.Windows.Forms.MenuItem fileItem;
	internal System.Windows.Forms.MenuItem newItem;
	internal System.Windows.Forms.MenuItem openItem;
	internal System.Windows.Forms.MenuItem saveItem;
	internal System.Windows.Forms.MenuItem optionsMenu;
	internal System.Windows.Forms.MenuItem viewItem;
	internal System.Windows.Forms.MenuItem toolsItem;

	// Declare a ContextMenu object and its items.
	internal System.Windows.Forms.ContextMenu contextMenu1;
	internal System.Windows.Forms.MenuItem cutItem;
	internal System.Windows.Forms.MenuItem copyItem;
	internal System.Windows.Forms.MenuItem pasteItem;

	public Form1() : base()
	{        
		this.mainMenu1 = new System.Windows.Forms.MainMenu();
		this.fileItem = new System.Windows.Forms.MenuItem();
		this.newItem = new System.Windows.Forms.MenuItem();
		this.openItem = new System.Windows.Forms.MenuItem();
		this.saveItem = new System.Windows.Forms.MenuItem();

		this.viewItem = new System.Windows.Forms.MenuItem();
		this.toolsItem = new System.Windows.Forms.MenuItem();

		this.optionsMenu = new System.Windows.Forms.MenuItem();
		this.toolsItem = new System.Windows.Forms.MenuItem();
		this.viewItem = new System.Windows.Forms.MenuItem();

		this.contextMenu1 = new System.Windows.Forms.ContextMenu();
		this.cutItem = new System.Windows.Forms.MenuItem();
		this.copyItem = new System.Windows.Forms.MenuItem();
		this.pasteItem = new System.Windows.Forms.MenuItem();

		//Add file menu item and options menu item to the MainMenu.
		this.mainMenu1.MenuItems.AddRange(
			new System.Windows.Forms.MenuItem[]
			{this.fileItem, this.optionsMenu});

		// Initialize the file menu and its contents.
		this.fileItem.Index = 0;
		this.fileItem.Text = "File";
		this.newItem.Index = 0;
		this.newItem.Text = "New";
		this.openItem.Index = 1;
		this.openItem.Text = "Open";
		this.saveItem.Index = 2;
		this.saveItem.Text = "Save";


		// Set the merge order of fileItem to 2 so it has a lower priority 
		// on the merged menu.
		this.fileItem.MergeOrder = 2;

		//Add the new items to the fileItem menu item collection.
		this.fileItem.MenuItems.AddRange(new MenuItem[]
			{this.newItem, this.openItem, this.saveItem});
		

		// Initalize the optionsMenu item and its contents.
		this.optionsMenu.Index = 1;
		this.optionsMenu.Text = "Options";

		this.viewItem.Index = 0;
		this.viewItem.Text = "View";
		this.toolsItem.Index = 1;
		this.toolsItem.Text = "Tools";

		// Set mergeOrder property to 1, so it has a higher priority than
		// the fileItem on the merged menu.
		this.optionsMenu.MergeOrder = 1;

		//Add view and tool items to the optionsItem menu item.
		this.optionsMenu.MenuItems.AddRange(new MenuItem[]
			{this.viewItem, this.toolsItem});

		// Initialize the menu items for the shortcut menu.
		this.cutItem.Index = 0;
		this.cutItem.Text = "Cut";
		this.cutItem.MergeOrder = 0;
		this.copyItem.Index = 1;
		this.copyItem.Text = "Copy";
		this.copyItem.MergeOrder = 0;
		this.pasteItem.Index = 2;
		this.pasteItem.Text = "Paste";
		this.pasteItem.MergeOrder = 0;

		// Add menu items to the shortcut menu.
		this.contextMenu1.MenuItems.AddRange(new MenuItem[]
			{cutItem, copyItem, pasteItem});

		// Add the mainMenu1 items to the shortcut menu as well, by
		// calling the MergeMenu method.
		contextMenu1.MergeMenu(mainMenu1);

		//Initialize the form.
		this.ClientSize = new System.Drawing.Size(292, 266);
		this.Name = "Form1";
		this.Text = "Right click on form for merged menu.";
		
		// Associate the event-handling method with the
		// MouseDown event.
		this.MouseDown +=new MouseEventHandler(Form1_MouseDown);

		// Add mainMenu1 to the form.
		this.Menu = mainMenu1;
	}

	private void Form1_MouseDown(object sender, MouseEventArgs e)
	{

		// Check for a right mouse click.
		if (e.Button==MouseButtons.Right)

			// Display a merged menu containing items from mainMenu1 
			// and contextMenu1.
		{
			contextMenu1.Show(this, new System.Drawing.Point(30, 30));
		}
	}

	[System.STAThreadAttribute]
	public static void Main()
	{
		Application.Run(new Form1());
	}


}

// The following code example demonstrates using the MenuItem 
// Merge-Order property to control the way a merged menu is displayed.

import System.Windows.Forms.*;

public class Form1 extends System.Windows.Forms.Form
{
    //Declare a MainMenu object and its items.
    System.Windows.Forms.MainMenu mainMenu1;
    System.Windows.Forms.MenuItem fileItem;
    System.Windows.Forms.MenuItem newItem;
    System.Windows.Forms.MenuItem openItem;
    System.Windows.Forms.MenuItem saveItem;
    System.Windows.Forms.MenuItem optionsMenu;
    System.Windows.Forms.MenuItem viewItem;
    System.Windows.Forms.MenuItem toolsItem;

    // Declare a ContextMenu object and its items.
    System.Windows.Forms.ContextMenu contextMenu1;
    System.Windows.Forms.MenuItem cutItem;
    System.Windows.Forms.MenuItem copyItem;
    System.Windows.Forms.MenuItem pasteItem;

    public Form1()
    {
        super();
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.fileItem = new System.Windows.Forms.MenuItem();
        this.newItem = new System.Windows.Forms.MenuItem();
        this.openItem = new System.Windows.Forms.MenuItem();
        this.saveItem = new System.Windows.Forms.MenuItem();

        this.viewItem = new System.Windows.Forms.MenuItem();
        this.toolsItem = new System.Windows.Forms.MenuItem();

        this.optionsMenu = new System.Windows.Forms.MenuItem();
        this.toolsItem = new System.Windows.Forms.MenuItem();
        this.viewItem = new System.Windows.Forms.MenuItem();

        this.contextMenu1 = new System.Windows.Forms.ContextMenu();
        this.cutItem = new System.Windows.Forms.MenuItem();
        this.copyItem = new System.Windows.Forms.MenuItem();
        this.pasteItem = new System.Windows.Forms.MenuItem();
        //Add file menu item and options menu item to the MainMenu.
        this.mainMenu1.get_MenuItems().AddRange(
            new System.Windows.Forms.MenuItem[]{this.fileItem,this.optionsMenu});
        // Initialize the file menu and its contents.
        this.fileItem.set_Index(0);
        this.fileItem.set_Text("File");
        this.newItem.set_Index(0);
        this.newItem.set_Text("New");
        this.openItem.set_Index(1);
        this.openItem.set_Text("Open");
        this.saveItem.set_Index(2);
        this.saveItem.set_Text("Save");
        // Set the merge order of fileItem to 2 so it has a lower priority 
        // on the merged menu.
        this.fileItem.set_MergeOrder(2);
        //Add the new items to the fileItem menu item collection.
        this.fileItem.get_MenuItems().AddRange(new MenuItem[]
            { this.newItem, this.openItem, this.saveItem });
        // Initalize the optionsMenu item and its contents.
        this.optionsMenu.set_Index(1);
        this.optionsMenu.set_Text("Options");

        this.viewItem.set_Index(0);
        this.viewItem.set_Text("View");
        this.toolsItem.set_Index(1);
        this.toolsItem.set_Text("Tools");
        // Set mergeOrder property to 1, so it has a higher priority than
        // the fileItem on the merged menu.
        this.optionsMenu.set_MergeOrder(1);
        //Add view and tool items to the optionsItem menu item.
        this.optionsMenu.get_MenuItems().AddRange(new MenuItem[]
            { this.viewItem, this.toolsItem });
        // Initialize the menu items for the shortcut menu.
        this.cutItem.set_Index(0);
        this.cutItem.set_Text("Cut");
        this.cutItem.set_MergeOrder(0);
        this.copyItem.set_Index(1);
        this.copyItem.set_Text("Copy");
        this.copyItem.set_MergeOrder(0);
        this.pasteItem.set_Index(2);
        this.pasteItem.set_Text("Paste");
        this.pasteItem.set_MergeOrder(0);
        // Add menu items to the shortcut menu.
        this.contextMenu1.get_MenuItems().AddRange(new MenuItem[]
            { cutItem, copyItem, pasteItem });
        // Add the mainMenu1 items to the shortcut menu as well, by
        // calling the MergeMenu method.
        contextMenu1.MergeMenu(mainMenu1);
        //Initialize the form.
        this.set_ClientSize(new System.Drawing.Size(292, 266));
        this.set_Name("Form1");
        this.set_Text("Right click on form for merged menu.");
        // Associate the event-handling method with the
        // MouseDown event.
        this.add_MouseDown(new MouseEventHandler(Form1_MouseDown));
        // Add mainMenu1 to the form.
        this.set_Menu(mainMenu1);
    } //Form1

    private void Form1_MouseDown(Object sender, MouseEventArgs e)
    {
        // Check for a right mouse click.
        if (e.get_Button().Equals(get_MouseButtons().Right)) {
            // Display a merged menu containing items from mainMenu1 
            // and contextMenu1.
            contextMenu1.Show(this, new System.Drawing.Point(30, 30));
        }
    } //Form1_MouseDown

    /** @attribute System.STAThreadAttribute()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main
} //Form1

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

Community Additions

ADD
Show:
© 2014 Microsoft