How to: Change the Default Customization Form's Behavior
- 3 minutes to read
The following example shows how to change the default Customization Form’s behavior by handling the BarManager.CreateCustomizationForm event. In the example, the default Reset button within the Customization Form is replaced with a new “Custom Reset” button.
To change the default Customization Form’s behavior, a new Customization Form is created by inheriting from the CustomizationForm class. By default, this form serves as a container for a tabbed control (CustomizationControl) that displays the Toolbars, Commands and Options pages. This control is assigned to the form when the form is created. In some cases, you may want to derive from the CustomizationControl class to change its appearance and then supply this custom control to your custom Customization Form.
In this example, the custom CustomizationForm uses the default CustomizationControl object. The default Reset button is hidden, and a new “Custom Reset” button is created at the default Reset button position.
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);
}
private void barManager1_CreateCustomizationForm(object sender, CreateCustomizationFormEventArgs e) {
BarManager barManager = sender as BarManager;
e.CustomizationForm = new MyCustomizationForm(e.CustomizationControl.Clone(), barManager.GetController().LookAndFeel.ActiveLookAndFeel);
}
class MyCustomizationForm : CustomizationForm {
public MyCustomizationForm(CustomizationControl customizationControl, UserLookAndFeel lookAndFeel)
: base(customizationControl, lookAndFeel) {
}
public override void Init(DevExpress.XtraBars.BarManager manager) {
base.Init(manager);
// 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("Custom reset");
}
}