JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Merging MDI Menus

Here's a problem-let's say you have an MDI program that does spell checking, but of course, you don't want any spell checking done unless a document is open. To make matters worse, MDI children are not supposed to display their own menu systems at all. How can you set things up so that a Spell Checking menu item appears in the main menu system only when an MDI child window is open?

You could create the Spell Checking menu item and keep track if any MDI children are open or not, and use the menu item's Visible property to make it appear or disappear as appropriate, but there's an easier way. All you need to do is to give the MDI children menus, and specify how to merge those menus with the MDI parent when a child MDI window appears in the MDI parent. This way, new menu items will appear in the parent's menu system as appropriate when child windows are open.

There are two properties that specify how MDI child menus merge with the MDI parent's menu system: MergeType and MergeOrder, which are properties of MenuItem objects. MergeType specifies how a menu item will be merged with its parent's menu system, and can take these values from the MenuMerge enumeration:

  • Add- The menu item is added to the existing menu items in a merged menu.

  • MergeItems- All submenu items of this menu item are merged with those of existing menu items (at the same position) in a merged menu.

  • Remove- The menu item is not to be included in a merged menu.

  • Replace- The menu item replaces an existing menu item at the same position.

And the MergeOrder property sets the order of the merged items, in case you want to specify that order.

You can see how this works in the MDIMenus example on the CD-ROM. In this case, I've given the MDI parent's Edit menu one item: Cut, and the MDI child's Edit menu one item: Copy.

To merge these menus, I set the MergeType property of the MDI child's Edit menu to MergeItems, and set the MergeType property of the Copy item in that menu to Add. Then I set the MergeType of the Edit menu in the MDI parent to MergeItems and the MergeType property of the Cut item in that menu to Add. Now when I run the program and display an MDI child window, the two menu items, Cut and Copy, are merged in the MDI parent's Edit menu, as you see in Figure 9.16, and the MDI child doesn't display any menu system at all.


Figure 9.16: Merging MDI menu items.
Tip 

You can also use the MergeMenu method to merge menu items in code.

Related solution:

Found on page:

Creating Multiple Document Interface (MDI) Applications

186

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor