工具栏表单
工具栏表单是XtraForm的扩展版本,它允许您直接向表单标题栏添加栏项。
下图展示了一个样例Toolbar表单,表单标题栏中有不同类型的栏项(常规按钮、编辑项、检查项和皮肤菜单)。
ToolbarForm是XtraForm类的后代,并共享它的所有特性。
将表单转换为工具栏表单
要将标准或任何DevExpress表单转换为工具栏表单,调用智能标签菜单并选择Convert to Toolbar Form选项。
隐藏表单标题
可以显示没有标题的工具栏表单(Form.Text属性)。要做到这一点,禁用ShowText设置,下面是DevExpress的Visual Studio Inspired UI Demo的截图,演示了一个没有可见标题的工具栏表单。
在设计时向表单标题栏添加栏项
工具栏表单的标题栏的填充方式与将栏项添加到常规工具栏的方式相同:表单的标题栏两端有两个区域可以容纳项,点击“[Add]”按钮创建新项目。
您可以在设计时拖放项目来重新排列它们,并从一个标题栏区域移动到另一个标题栏区域。
在Code.Satellite 控件中创建工具栏表单
工具栏表单有两个必需的附属控件——ToolbarFormControl和ToolbarFormManager。
- ToolbarFormControl ——表单的标题栏,显示添加到ToolbarFormControl.TitleItemLinks 集合中的栏项,使用BarItem.Alignment 属性选择此项目是停靠在ToolbarFormControl的左边缘还是右边缘。
- ToolbarFormManager——表单的内部BarManager,拥有显示在ToolbarFormControl中的栏项。
要将现有表单转换为Toolbar forms或在代码中创建新的Toolbar forms,需要手动创建这些组件。
C# :
ToolbarForm myForm = new ToolbarForm(); myForm.Size = new Size(800, 600); myForm.Text = "Toolbar Form"; ToolbarFormManager tfcManager = new ToolbarFormManager() { Form = myForm }; ToolbarFormControl tfcHeader = new ToolbarFormControl() { ToolbarForm = myForm, Manager = tfcManager}; myForm.Controls.Add(tfcHeader); myForm.ToolbarFormControl = tfcHeader; //create four buttons BarButtonItem item1 = new BarButtonItem(tfcManager, "Button 1"); BarButtonItem item2 = new BarButtonItem(tfcManager, "Button 2"); BarButtonItem item3 = new BarButtonItem(tfcManager, "Button 3"); BarButtonItem item4 = new BarButtonItem(tfcManager, "Button 4"); //buttons 3 and 4 will be docked to the ToolbarFormControl's right edge item3.Alignment = item4.Alignment = BarItemLinkAlignment.Right; //Out of two items added to the TitleItemLinks collection, the item that was added first //will be closer to the form edge. For that reason, you need to populate the right area //backwards, i.e. start with rightmost item tfcHeader.TitleItemLinks.AddRange(new BarItem[] { item1, item2, item4, item3}); myForm.Show();
VB.NET:
Dim myForm As New ToolbarForm() myForm.Size = New Size(800, 600) myForm.Text = "Toolbar Form" Dim tfcManager As New ToolbarFormManager() With {.Form = myForm} Dim tfcHeader As New ToolbarFormControl() With {.ToolbarForm = myForm, .Manager = tfcManager} myForm.Controls.Add(tfcHeader) myForm.ToolbarFormControl = tfcHeader 'create four buttons Dim item1 As New BarButtonItem(tfcManager, "Button 1") Dim item2 As New BarButtonItem(tfcManager, "Button 2") Dim item3 As New BarButtonItem(tfcManager, "Button 3") Dim item4 As New BarButtonItem(tfcManager, "Button 4") 'buttons 3 and 4 will be docked to the ToolbarFormControl's right edge item4.Alignment = BarItemLinkAlignment.Right item3.Alignment = item4.Alignment 'Out of two items added to the TitleItemLinks collection, the item that was added first 'will be closer to the form edge. For that reason, you need to populate the right area 'backwards, i.e. start with rightmost item tfcHeader.TitleItemLinks.AddRange(New BarItem() { item1, item2, item4, item3}) myForm.Show()
合并标题栏项目
在MDI应用程序中,当子工具栏表单最大化时,其标题栏中的栏项将与父表单的栏项合并。
- 使用MergeStyle属性指定何时合并标题栏项。
- 处理可选的合并和取消合并来实现任何自定义逻辑和手动调整标题栏。