Merging menu items for MDI windows

How can I combine the menu items of the parent form and child form with the same menu name?

+4
source share
1 answer

Set the MergeAction menu items to "MatchOnly."

Added

Since this may seem a bit complicated, I will add a list of steps to make a simple example.

  • Create a new Windows Forms application.
  • Add a new Windows form and leave its name Form2.
  • Open the constructor of Form1 (if it is not already open).
  • Click on the form and set Form1 IsMdiContainer to True.
  • Open the toolbar and add MenuStrip to Form1.
  • In the Type Here field, enter & File
  • In the subtype "Type here" enter type A
  • In the subtype "Type here" enter type B
  • Your MDI container (Form1) should have a File menu with items A and B.
  • Double-click item A to add a click handler.
  • Add new Form2 { MdiParent = this }.Show(); to the handler method.
  • Open the Form2 constructor.
  • Open the toolbar and add a MenuStrip to form2.
  • Note. . See below for information on a visible property in Form2 MenuStrip, which at this point can be set to False.
  • In the Type Here field, enter & File
  • In the subtype "Type here" enter type C
  • Your MDI child (Form2) should have a File menu with item C.
  • Click on the "File" menu item and in the properties window is set to MergeAction to MatchOnly.
  • Run the program.

Please note that the menu items "File" - "A" and "B".

Click File β†’ A to create a child window.

Notice that the File menu in the container now contains A, B, and C.

Please note that the child has but no items in the File menu. This is because C has been combined.

Now you can set the child property MenuStrip.Visible to False so that the child does not display the menu. It’s convenient to leave this as β€œTrue” when designing your menus, so that you can make sure that all the elements of the children's menu have been merged correctly (they will disappear from the child menu).

You can use the MergeIndex property to control how children are merged into a container.

+12
source

All Articles