工具欄表單
工具欄表單是XtraForm的擴(kuò)展版本,它允許您直接向表單標(biāo)題欄添加欄項(xiàng)。
下圖展示了一個(gè)樣例Toolbar表單,表單標(biāo)題欄中有不同類型的欄項(xiàng)(常規(guī)按鈕、編輯項(xiàng)、檢查項(xiàng)和皮膚菜單)。

ToolbarForm是XtraForm類的后代,并共享它的所有特性。
將表單轉(zhuǎn)換為工具欄表單
要將標(biāo)準(zhǔn)或任何DevExpress表單轉(zhuǎn)換為工具欄表單,調(diào)用智能標(biāo)簽菜單并選擇Convert to Toolbar Form選項(xiàng)。

隱藏表單標(biāo)題
可以顯示沒有標(biāo)題的工具欄表單(Form.Text屬性)。要做到這一點(diǎn),禁用ShowText設(shè)置,下面是DevExpress的Visual Studio Inspired UI Demo的截圖,演示了一個(gè)沒有可見標(biāo)題的工具欄表單。

在設(shè)計(jì)時(shí)向表單標(biāo)題欄添加欄項(xiàng)
工具欄表單的標(biāo)題欄的填充方式與將欄項(xiàng)添加到常規(guī)工具欄的方式相同:表單的標(biāo)題欄兩端有兩個(gè)區(qū)域可以容納項(xiàng),點(diǎn)擊“[Add]”按鈕創(chuàng)建新項(xiàng)目。

您可以在設(shè)計(jì)時(shí)拖放項(xiàng)目來重新排列它們,并從一個(gè)標(biāo)題欄區(qū)域移動(dòng)到另一個(gè)標(biāo)題欄區(qū)域。
在Code.Satellite 控件中創(chuàng)建工具欄表單
工具欄表單有兩個(gè)必需的附屬控件——ToolbarFormControl和ToolbarFormManager。
- ToolbarFormControl ——表單的標(biāo)題欄,顯示添加到ToolbarFormControl.TitleItemLinks 集合中的欄項(xiàng),使用BarItem.Alignment 屬性選擇此項(xiàng)目是停靠在ToolbarFormControl的左邊緣還是右邊緣。
- ToolbarFormManager——表單的內(nèi)部BarManager,擁有顯示在ToolbarFormControl中的欄項(xiàng)。
要將現(xiàn)有表單轉(zhuǎn)換為Toolbar forms或在代碼中創(chuàng)建新的Toolbar forms,需要手動(dòng)創(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()
合并標(biāo)題欄項(xiàng)目
在MDI應(yīng)用程序中,當(dāng)子工具欄表單最大化時(shí),其標(biāo)題欄中的欄項(xiàng)將與父表單的欄項(xiàng)合并。
- 使用MergeStyle屬性指定何時(shí)合并標(biāo)題欄項(xiàng)。
- 處理可選的合并和取消合并來實(shí)現(xiàn)任何自定義邏輯和手動(dòng)調(diào)整標(biāo)題欄。