Back to Devexpress

XtraTabControl.CustomHeaderButtonClick Event

windowsforms-devexpress-dot-xtratab-dot-xtratabcontrol-7ccdf52a.md

latest4.7 KB
Original Source

XtraTabControl.CustomHeaderButtonClick Event

Occurs when a custom header button is clicked.

Namespace : DevExpress.XtraTab

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Behavior")]
public event CustomHeaderButtonEventHandler CustomHeaderButtonClick
vb
<DXCategory("Behavior")>
Public Event CustomHeaderButtonClick As CustomHeaderButtonEventHandler

Event Data

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

PropertyDescription
ActivePageGets an active tab page within the tab control.
ButtonGets the currently processed custom header button.

Remarks

A tab control has built-in header buttons (see the XtraTabControl.HeaderButtons property). You can also add any number of custom header buttons to the tab control using the XtraTabControl.CustomHeaderButtons property. Each custom button is a CustomHeaderButton object that provides a variety of properties such as EditorButton.Caption, EditorButton.Kind, EditorButton.Tag, etc.

After you have added custom buttons, you need to add a functionality to them. Handle the CustomHeaderButtonClick event to perform actions on button clicking.

Example

The example demonstrates how to add two custom header buttons to a tab control and use the XtraTabControl.CustomHeaderButtonClick event to add or remove tabs.

csharp
using DevExpress.XtraTab;
using DevExpress.XtraTab.Buttons;
using DevExpress.XtraEditors.Controls;

private void Form1_Load(object sender, EventArgs e) {
    xtraTabControl1.CustomHeaderButtons.Add(new CustomHeaderButton(ButtonPredefines.Plus));
    xtraTabControl1.CustomHeaderButtons.Add(new CustomHeaderButton(ButtonPredefines.Minus));
}

int counter = 0;
private void xtraTabControl1_CustomHeaderButtonClick(object sender, DevExpress.XtraTab.ViewInfo.CustomHeaderButtonEventArgs e) {
    if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus) {
        xtraTabControl1.TabPages.Add("page" + (++counter));
    }
    else {
        if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Minus) {
            xtraTabControl1.TabPages.Remove(e.ActivePage as XtraTabPage);
        }
    }
}
vb
Imports DevExpress.XtraTab
Imports DevExpress.XtraTab.Buttons
Imports DevExpress.XtraEditors.Controls

Public Class Form1
    Dim counter As Integer = 0
    Private Sub XtraTabControl1_CustomHeaderButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraTab.ViewInfo.CustomHeaderButtonEventArgs) Handles XtraTabControl1.CustomHeaderButtonClick
        If e.Button.Kind = ButtonPredefines.Plus Then
            counter = counter + 1
            XtraTabControl1.TabPages.Add("page" + counter.ToString)
        Else
            If e.Button.Kind = ButtonPredefines.Minus Then
                XtraTabControl1.TabPages.Remove(e.ActivePage)
            End If
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        XtraTabControl1.CustomHeaderButtons.Add(New CustomHeaderButton(ButtonPredefines.Plus))
        XtraTabControl1.CustomHeaderButtons.Add(New CustomHeaderButton(ButtonPredefines.Minus))
    End Sub
End Class

See Also

CustomHeaderButtons

XtraTabControl Class

XtraTabControl Members

DevExpress.XtraTab Namespace