windowsforms-1099-controls-and-libraries-ribbon-bars-and-menu-bars-mdi-merging.md
MDI Bar Merging combines links from parent and child window toolbars in MDI applications.
By default, only main menus merge automatically. Regular and status bars must be merged manually.
The Bar Manager does not merge items whose Visibility is disabled. Set the BarManager.AllowMergeInvisibleLinks property to true to change this behavior.
Note
The BarManager.AllowMergeInvisibleLinks property is hidden from IntelliSense and from the Properties window; you should set it manually in code.
Create a sample MDI application based on standard or DevExpress forms.
Add BarManager components to both parent and child MDI windows. Create main menus, status and regular bars, then populate them.
Run the application to see the main menus merging automatically.
BarManagers merge immediately after the application starts. To change this behavior and force BarManagers to merge only when a child window activates or maximizes, utilize the BarManager.MdiMenuMergeStyle property for the parent manager. Using the same property, you can also turn bar merging off.
There are now two “Help” sub-menus, one belongs to the parent main menu, the second belongs to the child main menu.
Parent and child toolbar links are arranged in the same order these links were in their original toolbars. To re-arrange these links, utilize the BarItem.MergeOrder property.
Handle the parent BarManager’s BarManager.Merge and BarManager.UnMerge events and run the application. If you have left the BarManager.MdiMenuMergeStyle property in its default Always value, regular and status toolbars of child MDI forms will now be hidden.
In the BarManager.Merge event handler, call the Bar.Merge method for a parent toolbar to populate it with item links of a specific child toolbar. Bar Managers merge toolbars by copying item links from one existing toolbar to another, you cannot make an entire toolbar swap its owners. Moreover, each bar can merge with one child toolbar only. With that being said, for every child toolbar merged you have to create a corresponding host toolbar in a parent Bar Manager. If a parent Manager has no fitting toolbars, you can either create fake toolbars dynamically on the BarManager.Merge event…
To allow toolbars to undo your manual merging when needed, call the Bar.UnMerge method on the BarManager.UnMerge event. The UnMerge method takes no parameters, it returns all merged item links back to their original owners. Depending on whether you have created host parent toolbars at design time or dynamically at runtime, you will need to hide these toolbars or dispose of them respectively.
After both Merge and Unmerge event handlers are ready, run the application to see the result.
The Application UI Manager, a component for building advanced multi-document interfaces, provides the DocumentManager.RibbonAndBarsMergeStyle property. When this property equals RibbonAndBarsMergeStyle.Default, merging is entirely managed by a parent Bar Manager and its BarManager.MdiMenuMergeStyle setting. Other property values affect the merging outcome as follows.
In Tabbed View.
| |
DocumentManager.RibbonAndBarsMergeStyle = Always
|
DocumentManager.RibbonAndBarsMergeStyle = WhenNotFloating
| |
BarManager.MdiMenuMergeStyle = Always
|
Any currently active Document merges its toolbars.
|
Only toolbars from active tabs merge.
| |
BarManager.MdiMenuMergeStyle = OnlyWhenChildMaximized
|
Toolbars do not merge.
| |
BarManager.MdiMenuMergeStyle = WhenChildActivated
|
Any currently active Document merges its toolbars.
|
Only toolbars from active tabs merge.
| |
BarManager.MdiMenuMergeStyle = Never
|
Toolbars do not merge
|
In Native MDI View.
| |
DocumentManager.RibbonAndBarsMergeStyle = Always
|
DocumentManager.RibbonAndBarsMergeStyle = WhenNotFloating
| |
BarManager.MdiMenuMergeStyle = Always
|
Toolbars from any active MDI window merge.
| |
BarManager.MdiMenuMergeStyle = OnlyWhenChildMaximized
|
Toolbars do not merge.
| |
BarManager.MdiMenuMergeStyle = WhenChildActivated
|
Toolbars from any active MDI window merge.
| |
BarManager.MdiMenuMergeStyle = Never
|
Toolbars do not merge
|
See Also