Bar

BarManager.Merge Event

Allows you to customize menus and bars when a child MDI form is activated or maximized (depending on the BarManager.MdiMenuMergeStyle property value).

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v20.1.dll

Declaration

[DXCategory("Events")]
public event BarManagerMergeEventHandler Merge
<DXCategory("Events")>
Public Event Merge As BarManagerMergeEventHandler

Event Data

The Merge event's data class is BarManagerMergeEventArgs. The following properties provide information specific to this event:

Property Description
ChildManager Gets the Bar Manager of a child MDI form for which the merge mechanism is invoked.

Remarks

In an MDI application, XtraBars give you the ability to merge the bars of parent and child MDI forms, i.e. combine bar links belonging to different Bar Managers.

The merge mechanism is invoked according to the BarManager's BarManager.MdiMenuMergeStyle property that resides in the parent form. This property allows you to disable merge operations and enable them when a child form is activated or maximized. Similarly, the corresponding unmerge operations will occur when a child form becomes inactive or when it is restored or minimized from its maximized view.

Two things happen when the merge mechanism is invoked:

  • the main menus of the parent and child MDI forms are merged automatically. This does not occur if the child form does not have a BarManager.
  • the Merge event is fired and this allows you to merge other bars belonging to the parent and child MDI forms. The BarManager.UnMerge event allows you to undo actions made via the Merge event.

To merge and unmerge two bars belonging to different BarManagers, you can use the Bar.Merge and Bar.UnMerge methods.

Refer to the MDI Merging document for more information.

Examples

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();
}
See Also