工具欄表單
工具欄表單是XtraForm的擴展版本,它允許您直接向表單標題欄添加欄項。
下圖展示了一個樣例Toolbar表單,表單標題欄中有不同類型的欄項(常規(guī)按鈕、編輯項、檢查項和皮膚菜單)。
ToolbarForm是XtraForm類的后代,并共享它的所有特性。
將表單轉(zhuǎn)換為工具欄表單
要將標準或任何DevExpress表單轉(zhuǎn)換為工具欄表單,調(diào)用智能標簽菜單并選擇Convert to Toolbar Form選項。
隱藏表單標題
可以顯示沒有標題的工具欄表單(Form.Text屬性)。要做到這一點,禁用ShowText設(shè)置,下面是DevExpress的Visual Studio Inspired UI Demo的截圖,演示了一個沒有可見標題的工具欄表單。
在設(shè)計時向表單標題欄添加欄項
工具欄表單的標題欄的填充方式與將欄項添加到常規(guī)工具欄的方式相同:表單的標題欄兩端有兩個區(qū)域可以容納項,點擊“[Add]”按鈕創(chuàng)建新項目。
您可以在設(shè)計時拖放項目來重新排列它們,并從一個標題欄區(qū)域移動到另一個標題欄區(qū)域。
在Code.Satellite 控件中創(chuàng)建工具欄表單
工具欄表單有兩個必需的附屬控件——ToolbarFormControl和ToolbarFormManager。
- ToolbarFormControl ——表單的標題欄,顯示添加到ToolbarFormControl.TitleItemLinks 集合中的欄項,使用BarItem.Alignment 屬性選擇此項目是停靠在ToolbarFormControl的左邊緣還是右邊緣。
- ToolbarFormManager——表單的內(nèi)部BarManager,擁有顯示在ToolbarFormControl中的欄項。
要將現(xiàn)有表單轉(zhuǎn)換為Toolbar forms或在代碼中創(chuàng)建新的Toolbar forms,需要手動創(chuàng)建這些組件。
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應(yīng)用程序中,當(dāng)子工具欄表單最大化時,其標題欄中的欄項將與父表單的欄項合并。
- 使用MergeStyle屬性指定何時合并標題欄項。
- 處理可選的合并和取消合并來實現(xiàn)任何自定義邏輯和手動調(diào)整標題欄。