Back to Devexpress

BarManager.CreateCustomizationForm Event

windowsforms-devexpress-dot-xtrabars-dot-barmanager-4bd88553.md

latest6.9 KB
Original Source

BarManager.CreateCustomizationForm Event

Occurs before the Customization Window is displayed.

Namespace : DevExpress.XtraBars

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event CreateCustomizationFormEventHandler CreateCustomizationForm
vb
<DXCategory("Events")>
Public Event CreateCustomizationForm As CreateCustomizationFormEventHandler

Event Data

The CreateCustomizationForm event's data class is CreateCustomizationFormEventArgs. The following properties provide information specific to this event:

PropertyDescription
CustomizationControlA BarManager that owns the customization form.
CustomizationFormGets or sets the dialog used as a Customization Form for a specific BarManager.

Remarks

Use this event to replace the default Customization Window with your own. To do so, assign your own customization dialog to the event’s CreateCustomizationFormEventArgs.CustomizationForm parameter.

For more information about the default Customization Window, see the Runtime Customization document.

Example

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.

csharp
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");
    }
}
vb
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)
    Dim barManager as BarManager = sender
    e.CustomizationForm = New MyCustomizationForm(e.CustomizationControl.Clone(), barManager.GetController().LookAndFeel.ActiveLookAndFeel)
End Sub

Friend Class MyCustomizationForm
    Inherits CustomizationForm
    Public Sub New(ByVal customizationControl As CustomizationControl, ByVal lookAndFeel As UserLookAndFeel)
        MyBase.New(customizationControl, 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("Custom reset")
    End Sub
End Class

See Also

Runtime Customization

BarManager Class

BarManager Members

DevExpress.XtraBars Namespace