Skip to main content
.NET Framework 4.5.2+

How to: Access the Ribbon Control

  • 2 minutes to read

This topic demonstrates how to access the Ribbon control used to show the WinForms application menu when the IModelOptionsWin.FormStyle property is set to Ribbon (when the ribbon interface is enabled). Refer to the How to: Customize Action Controls topic to learn how to customize bar items.

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

  1. Create a new WindowController in the WinForms module’s Controllers folder.
  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 RibbonForm. Use the RibbonForm.Ribbon property to access the RibbonControl object. For instance, you can specify the minimum allowed page header’s width using the RibbonControl.PageHeaderMinWidth property, and hide the Expand/Collapse button using the RibbonControl.ShowExpandCollapseButton property.
  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.XtraBars.Ribbon;
using DevExpress.Utils;
// ...
public class RibbonCustomizationWindowController : WindowController {
    protected override void OnActivated() {
        base.OnActivated();
        Window.TemplateChanged += Window_TemplateChanged;
    }
    private void Window_TemplateChanged(object sender, EventArgs e) {
        RibbonForm ribbonForm = Frame.Template as RibbonForm;
        if (ribbonForm != null && ribbonForm.Ribbon != null) {
            RibbonControl ribbon = ribbonForm.Ribbon;
            ribbon.PageHeaderMinWidth = 100;
            ribbon.ShowExpandCollapseButton = DefaultBoolean.False;
        }
    }
    protected override void OnDeactivated() {
        Window.TemplateChanged -= Window_TemplateChanged;
        base.OnDeactivated();
    }
}

Run the application to ensure that Ribbon control customizations are applied.