How to: Access the Ribbon Control 如何:访问功能区控件

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.

本主题演示如何在 IModelOptionsWin.FormStyle 属性设置为功能区(启用功能区界面时)访问用于显示 WinForms 应用程序菜单的功能区控件。请参阅"如何:自定义操作控制"主题,了解如何自定义栏项。

Tip 注意
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4027
在 DevExpress 代码示例数据库中提供了完整的示例项目http://www.devexpress.com/example=E4027

.

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.

按照以下步骤访问功能区控制对象并自定义其设置:

1. 在 WinForms 模块的控制器文件夹中创建新的窗口控制器。

2. 覆盖控制器的 On 已激活方法并订阅 Frame.模板更改事件。

3. 在模板更改事件处理程序中,确保 Frame.Template 的类型为功能区窗体。使用功能区窗体.功能区属性访问功能区控制对象。例如,可以使用功能区控制.pageHeaderMinWidth 属性指定允许的最小页页页眉宽度,并使用功能区控制.显示展开折叠按钮属性隐藏"展开/折叠"按钮。

4. 覆盖控制器的 OnDeon 已激活方法,并在停用控制器时取消订阅模板更改事件。

 

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.

运行应用程序以确保应用功能区控件自定义项。

原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Access-the-Ribbon-Control.html