The requested page is not available for the requested platform. You are viewing the content for Default platform.

How to: Access the Bar Manager

  • 2 min to read

WinForms applications use the Bar Manager to show an application's menu when the ribbon interface is disabled (see IModelOptionsWin.FormStyle), and to display a nested Frame's toolbar. This topic describes how to access the Bar Manager. Refer to the How to: Customize Action Controls topic to learn how to customize bar items.

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4027.

Follow the steps below to access the BarManager object and customize its settings:

  1. Create a new Controller in the WinForms module's Controllers folder. This Controller customizes Bar Managers in all Frames, including nested Frames (see NestedFrame).
  2. Override the Controller's OnActivated method and subscribe to the Frame.TemplateChanged event.
  3. In the TemplateChanged event handler, ensure that the Frame.Template's type is IBarManagerHolder. Cast the Template to the IBarManagerHolder type and use the IBarManagerHolder.BarManager property to access the BarManager object. For instance, you can set the BarManager.AllowCustomization property to false to prohibit end-users from customizing a bar.
  4. Override the Controller's OnDeactivated method and unsubscribe from the TemplateChanged event when the Controller is deactivated.
using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.Controls;
using DevExpress.XtraBars;
// ...
public class BarManagerCustomizationWindowController : Controller {
    protected override void OnActivated() {
        base.OnActivated();
        Frame.TemplateChanged += Frame_TemplateChanged;
    }
    private void Frame_TemplateChanged(object sender, EventArgs e) {
        if (Frame.Template is IBarManagerHolder) {
            BarManager manager = ((IBarManagerHolder)Frame.Template).BarManager;
            manager.AllowCustomization = false;
        }
    }
    protected override void OnDeactivated() {
        Frame.TemplateChanged -= Frame_TemplateChanged;
        base.OnDeactivated();
    }
}

Run the application to ensure that bar customization is not allowed.

BarManager_AllowCustomization