Set the MergeAction of the File menu to Insert, and set the Mergelndex to 3, so it appears fourth on the list.Ħ. Add a Print menu item to the child's File menu.ĥ. Set the MergeAction of the File menu to MatchOnly.Ĥ. Make sure both MenuStrip controls have AllowMerge set to true (the default).ģ. To make this work with menu merging, take these steps:ġ. When a child is activated, you want to add the Print command just after the Save command. Merging submenus together takes a little more work.įor example, imagine you have a File menu in the parent, with a few basic commands (New, Open, Save, a separator, and Quit). Using the Append and Insert merge options, it's easy to insert new menus from the child into the parent (as described in Table 19-1). However, the top-level File menu will remain in the child window. For example, if you create a top-level File menu with a MatchOnly merge, and you place other items into this menu with other merge types (like Append or Insert), these subitems will be relocated into the parent's File menu, if it exists. This option is primarily useful for combining top-level menus or nested structures. MatchOnly Searches for a matching item in the parent menu, but doesn't perform any merging. If a match is found, that item is removed from the parent. Remove Searches for a matching item in the parent menu. The menu disappears from the child window. If the property is second, the merged item will be placed between the original first and second items, and so on. For example, if the property is 0, the merged item will be placed first in the menu. Insert Inserts the child item into the parent menu at the position indicated by the If no match is found, the menus aren't merged. If it finds a matching item, the parent menu (and its subitems) is replaced with the child menu (and its subitems). Replace Searches for a matching item in the parent menu. If you append several items, their order in the parent menu is the same as their order was in the child menu. Values from the MergeAction EnumerationĪppend Adds the child menu to the end of the parent menu. Mergelndex is only used if you use a MergeAction of Insert. It takes one of the values shown in Table 19-1. (The MergeAction and Mergelndex properties of the menu items in the parent have no effect.) The most important of the two properties is MergeAction, which determines how each individual menu item is merged. Next, you need to consider the MergeAction and Mergelndex properties of the menu items in the child. For example, if you're performing merging between two main menus, the MenuStrip.AllowMerge property of both the source and destination menus must be true. For any merging to happen, the AllowMerge property of both top-level containers needs to be set true (which is the default value). Menu merging revolves around three properties: AllowMerge, MergeAction, and MergeIndex. ■Tip If you use merging with the ToolStrip and there is more than one possible destination for merging, your ToolStripItem objects are merged into the last ToolStrip (the one added to the Controls collection of the parent form last). However, you can't move a ToolStripItem into a MenuStrip, or a ToolStripMenu-Item into an ordinary ToolStrip through merging. Similarly, you can move a ToolStripItem from a ToolStrip in the child to a ToolStrip in the parent. For example, you perform menu merging to move a menu from the MenuStrip on the child to the MenuStrip on the parent. However, you can only merge between top-level containers of the same type. Interestingly enough, both the MenuStrip and the ToolStrip support menu merging. If you plan to merge the entire menu, you should set MenuStrip.Visible to false in the child window. ■Tip Even if you merge every top-level menu in a child window, the MenuStrip container remains, with its shaded background. As you move from one child to another, the menus are adjusted automatically.įigure 19-8 shows an example with a child menu named Document. This merging process happens whenever the child form gets focus (is activated). Using the default menu behavior, menu items from the child form are added to the right of the predefined menu items in the parent (and removed from the child menu). This behavior allows you to provide different options depending on the current view, but presents a centralized menu to the user. If you create a child form with a menu, that menu is added to the main menu when the child form is displayed. Another unique characteristic of MDI applications is their treatment of menus.
0 Comments
Leave a Reply. |