Assembly:DevExpress.XtraBars.v14.1.dll
BarManager 是 XtraBars Library.最重要元素。 It is a container for bar items, categories and bars. For every form you want to place bars on, you should place a BarManager component .
要在运行时激活自定义(工具管理)窗口 ,调用Customize 方法.
BarManager 提供保存和恢复工具布局到注册表的辅助工具. 保存布局, 调用 SaveToRegistry 方法, and RestoreFromRegistry 恢复布局. 在保存和加载之前,需指定注册表路径( RegistryPath 属性).
XtraBars 引入 BarAndDockingController 来保存程序总工具条的自定义和外观设置. BarAndDockingController 提供默认设置 . 也就是说这些设置都可以被独立设置覆盖。BarAndDockingController 允许你实现 centralized control over the bars settings. 默认所有工具条通过BarAndDockingController得到设置. 获取和定制默认控制器通过静态 BarAndDockingController.Default 属性或通过DefaultBarAndDockingController 组件.
If you need to provide different settings for bars residing within specific forms, as compared to bars within other forms, you need to create new BarAndDockingController objects and assign them to the Controller properties of the required BarManagers. In this case, bars will get their settings from this controller and not from the default controller. The GetController function returns the actual controller providing a bar's settings.
设计时拖放 BarManager 到窗体,所有控件公开 PopupContextMenu 扩展属性 (属性窗口中的标题像 'PopupContextMenu on barManager1')一样. 可以使用此属性给控件关联PopupMenu orRadialMenu . 右击时将显示该菜单
代码关联弹出菜单, 调用 SetPopupContextMenu 方法.
可以在弹出菜单显示前定制菜单,通过处理 QueryShowPopupMenu 事件
Note |
---|
某些特定复杂的控件such as XtraGrid and XtraTreeList 不公开 PopupContextMenu 属性, as these controls support different context menus for different visual elements. See the help documentation on these products to learn how to work with context menus in these controls. |
Note |
---|
不允许添加两个或多个 BarManager 组件到同一窗体或用户控件. |
Note |
---|
不推荐常规工具条 ( BarManager 组件) 和 RibbonControl 在同一窗体或用户控件中同时使用, 可能会冲突. |
示例1 :个人实践
新建窗体项目,拖动BarManager到窗体设计器,会自动显示菜单栏和工具栏和状态栏(都是XtraBars.Bar),默认name工具栏bar1,BarName=Tools,菜单栏bar2,BarName=Main Menu,状态栏bar3,BarName=Statusbar。
BarManager属性里只可以看到MainMenu和StatusBar。
因为每个Form仅有一个主菜单和状态栏,而ToolBar可以有多个,即自定义工具。(CustomBar)
How to obtain a value of the BarEditItem during editing
Object value=(barManager1.ActiveEditor as DevExpress.XtraEditors.ButtonEdit).EditValue;
工具栏通过Bars集合添加. 工具栏项通过 Bar.AddItem and Bar.AddItems 方法添加。
避免添加和定制工具栏和功能项时闪烁,处理定制的代码通过, BeginUpdate and EndUpdate 方法调用进行闭合操作。
添加子菜单通过单击,并选择添加Menu(BarSubItem),命名subMenuFile、subMenuEdit、subMenu+名称
添加菜单项通过选择具体的功能控件就OK,命名 空间类型+(子菜单名)+功能名,如buttonOpen、buttonViewOutput。
通过设计器将同一个功能项同时指向菜单和工具栏没找到?????
官方文档:示例展示如何通过代码创建工具条和工具条选项。
创建两个工具条-主菜单(工具条扩展到匹配窗口宽度)和常规工具条. 主菜单包含三个子菜单 (File, Edit and View), 每个有自己的功能项. 第二个工具条为工具栏,显示 Output 按钮, Output项也可以通过主菜单的View视图子菜单获取:
工具栏通过Bars集合添加. 工具栏项通过 Bar.AddItem and Bar.AddItems 方法添加。
避免添加和定制工具栏和功能项时闪烁,处理定制的代码通过, BeginUpdate and EndUpdate 方法调用进行闭合操作。
处理功能项的单击事件
private void btnViewOutput_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
//处理某一项
}
// 放在barManager的ItemClick处理,可以集中处理所有的
private void barManager1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
DevExpress.XtraBars.BarSubItem subMenu = e.Item as DevExpress.XtraBars.BarSubItem;
if (subMenu != null) return;
MessageBox.Show("Item '" + e.Item.Caption + "' has been clicked");
}
| ||||||
|
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
ComponentEditorContainer
BarManager
PrintBarManager
DevExpress.XtraBars.Ribbon.RibbonBarManager
DevExpress.XtraBars Namespace
Bar
BarItem
BarItemLink
BarAndDockingController
Bar Manager
Bar and Docking Controller