This documentation is archived and is not being maintained.

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)

property int MergeOrder {
	int get ();
	void set (int value);

Property Value

Type: System::Int32
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 namespace System::Windows::Forms;

//Declare a MainMenu object and its items. 
public ref class Form1: public System::Windows::Forms::Form
public private:
   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;

      : Form()
      this->mainMenu1 = gcnew System::Windows::Forms::MainMenu;
      this->fileItem = gcnew System::Windows::Forms::MenuItem;
      this->newItem = gcnew System::Windows::Forms::MenuItem;
      this->openItem = gcnew System::Windows::Forms::MenuItem;
      this->saveItem = gcnew System::Windows::Forms::MenuItem;
      this->viewItem = gcnew System::Windows::Forms::MenuItem;
      this->toolsItem = gcnew System::Windows::Forms::MenuItem;
      this->optionsMenu = gcnew System::Windows::Forms::MenuItem;
      this->toolsItem = gcnew System::Windows::Forms::MenuItem;
      this->viewItem = gcnew System::Windows::Forms::MenuItem;
      this->contextMenu1 = gcnew System::Windows::Forms::ContextMenu;
      this->cutItem = gcnew System::Windows::Forms::MenuItem;
      this->copyItem = gcnew System::Windows::Forms::MenuItem;
      this->pasteItem = gcnew System::Windows::Forms::MenuItem;

      //Add file menu item and options menu item to the MainMenu. 
      array<System::Windows::Forms::MenuItem^>^temp0 = {this->fileItem,this->optionsMenu};
      this->mainMenu1->MenuItems->AddRange( temp0 );

      // 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. 
      array<MenuItem^>^temp1 = {this->newItem,this->openItem,this->saveItem};
      this->fileItem->MenuItems->AddRange( temp1 );

      // 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. 
      array<MenuItem^>^temp2 = {this->viewItem,this->toolsItem};
      this->optionsMenu->MenuItems->AddRange( temp2 );

      // 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. 
      array<MenuItem^>^temp3 = {cutItem,copyItem,pasteItem};
      this->contextMenu1->MenuItems->AddRange( temp3 );

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

      //Initialize the form. 
      this->ClientSize = 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 += gcnew MouseEventHandler( this, &Form1::Form1_MouseDown );

      // Add mainMenu1 to the form. 
      this->Menu = mainMenu1;

   void Form1_MouseDown( Object^ /*sender*/, MouseEventArgs^ e )

      // Check for a right mouse click. 
      if ( e->Button == ::MouseButtons::Right )
         contextMenu1->Show( this, System::Drawing::Point( 30, 30 ) );


int main()
   Application::Run( gcnew Form1 );
	Merge-Order property to control the way a merged menu is displayed.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0