下面的示例展示了如何改变“自定义”窗体的默认行为。 在本例中,在“自定义”窗体中的默认“Reset(重置)”按钮被替换为新的执行自定义操作的“Custom Reset”按钮。
要改变“自定义”窗体的默认行为,需要新建一个继承于 CustomizationForm 类的“自定义”窗体。 在默认情况下,此窗体作为显示了“工具栏”、“命令”和“选项”页面的标签式控件的容器。 此控件由 CustomizationControl 类表示。 在创建窗体时,可以提供一个 CustomizationControl 对象,此对象的设置被设置为默认值。 或者可以从 CustomizationControl 类派生,修改新派生的自定义控件的外观,并且把它添加到定制的“自定义”窗体中。
在本示例中,我们从 CustomizationForm 类继承窗体,为它提供一个默认的 CustomizationControl 对象。 然后,隐藏默认的“Reset(重置)”按钮,并且在默认的“Reset(重置)”按钮的位置上新建一个按钮。
通过 BarManager.CreateCustomizationForm 事件,把定制的“自定义”窗体提供到 BarManager。
C# | 复制代码 |
---|---|
using DevExpress.XtraBars.Customization; using DevExpress.XtraBars.Localization; using DevExpress.LookAndFeel; using DevExpress.XtraEditors; using DevExpress.XtraBars; private void Form1_Load(object sender, EventArgs e) { barManager1.CreateCustomizationForm += new CreateCustomizationFormEventHandler(barManager1_CreateCustomizationForm); } void barManager1_CreateCustomizationForm(object sender, CreateCustomizationFormEventArgs e) { e.CustomizationForm = new MyCustomizationForm(BarLocalizer.Active.Customization.Clone(), barManager1.GetController().LookAndFeel.ActiveLookAndFeel); ; } class MyCustomizationForm : CustomizationForm { public MyCustomizationForm(CustomizationControl lmanager, UserLookAndFeel lookAndFeel) : base(lmanager, lookAndFeel) { } public override void Init(DevExpress.XtraBars.BarManager AManager) { base.Init(AManager); // Access and hide the default Reset button. SimpleButton btnReset = localizationManager.btResetBar; btnReset.Visible = false; // Create a new button that will be displayed at the position of the default Reset button. SimpleButton btnNewReset = new SimpleButton(); btnNewReset.Text = "Custom Reset"; btnNewReset.Parent = btnReset.Parent; btnNewReset.Size = btnReset.Size; btnNewReset.Location = btnReset.Location; btnNewReset.Click += new EventHandler(btnNewResetBar_Click); } void btnNewResetBar_Click(object sender, EventArgs e) { //... MessageBox.Show("some text"); } } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraBars.Customization Imports DevExpress.XtraBars.Localization Imports DevExpress.LookAndFeel Imports DevExpress.XtraEditors Imports DevExpress.XtraBars Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load AddHandler barManager1.CreateCustomizationForm, AddressOf barManager1_CreateCustomizationForm End Sub Private Sub barManager1_CreateCustomizationForm(ByVal sender As Object, _ ByVal e As CreateCustomizationFormEventArgs) e.CustomizationForm = New MyCustomizationForm(BarLocalizer.Active.Customization.Clone(), _ barManager1.GetController().LookAndFeel.ActiveLookAndFeel) End Sub Friend Class MyCustomizationForm Inherits CustomizationForm Public Sub New(ByVal lmanager As CustomizationControl, ByVal lookAndFeel As UserLookAndFeel) MyBase.New(lmanager, lookAndFeel) End Sub Public Overrides Sub Init(ByVal AManager As DevExpress.XtraBars.BarManager) MyBase.Init(AManager) ' Access and hide the default Reset button. Dim btnReset As SimpleButton = localizationManager.btResetBar btnReset.Visible = False ' Create a new button that will be displayed at the position of the default Reset button. Dim btnNewReset As SimpleButton = New SimpleButton() btnNewReset.Text = "Custom Reset" btnNewReset.Parent = btnReset.Parent btnNewReset.Size = btnReset.Size btnNewReset.Location = btnReset.Location AddHandler btnNewReset.Click, AddressOf btnNewResetBar_Click End Sub Private Sub btnNewResetBar_Click(ByVal sender As Object, ByVal e As EventArgs) '... MessageBox.Show("some text") End Sub End Class |