How to: Merge bars manually
- 2 minutes to read
Assume you have parent and child MDI forms. On each one you place a Bar Manager and create an Edit toolbar. When the child MDI form is activated, we want to merge these toolbars (XtraBars supports automatic merging of main menus only). For this purpose, the BarManager.Merge event is handled. Toolbars are merged using the Bar.Merge method.
When the child form becomes inactive (for instance, focus may move to another form), we need to restore the original main menu layout of the parent form. For this purpose, the Bar.UnMerge method is called in an BarManager.UnMerge event handler.
using DevExpress.XtraBars;
private void barManager1_Merge(object sender, BarManagerMergeEventArgs e) {
BarManager parentBarManager = sender as BarManager;
Bar childBar = e.ChildManager.Bars["Edit"];
Bar parentBar = parentBarManager.Bars["Edit"];
parentBar.Merge(childBar);
}
private void barManager1_UnMerge(object sender, BarManagerMergeEventArgs e) {
BarManager parentBarManager = sender as BarManager;
Bar parentBar = parentBarManager.Bars["Edit"];
parentBar.UnMerge();
}