Back to Devexpress

EditorButton.IsDefaultButton Property

windowsforms-devexpress-dot-xtraeditors-dot-controls-dot-editorbutton-58da27ca.md

latest6.5 KB
Original Source

EditorButton.IsDefaultButton Property

Gets or sets whether the button is the default button.

Namespace : DevExpress.XtraEditors.Controls

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[Browsable(false)]
public virtual bool IsDefaultButton { get; set; }
vb
<Browsable(False)>
Public Overridable Property IsDefaultButton As Boolean

Property Value

TypeDescription
Boolean

true if the button is the default button; otherwise, false.

|

Remarks

Default editor buttons are the buttons that are displayed by default. For instance, when a ButtonEdit is dropped onto a form, it displays a (…) button which is the default button. The button’s IsDefaultButton property specifies whether the button is the default button. This can be useful when creating custom editors with additional default buttons.

Example

The example below demonstrates how to create a custom button editor with default spin buttons.

csharp
class RepositoryItemMyButtonEdit : RepositoryItemButtonEdit {
    // ...
    public static void RegisterMyButtonEdit() {
        // ...
        EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo("MyButtonEdit", 
        typeof(MyButtonEdit), typeof(RepositoryItemMyButtonEdit), 
        typeof(DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo), 
        new DevExpress.XtraEditors.Drawing.ButtonEditPainter(), 
        true, null, typeof(DevExpress.Accessibility.ButtonEditAccessible)));
    }
    private void AddDefaultButton(EditorButton btn, Keys keys) {
        btn.IsLeft = true;
        btn.Shortcut = new DevExpress.Utils.KeyShortcut(keys);
        btn.IsDefaultButton = true;
        Buttons.Add(btn);
    }
    public override void CreateDefaultButton() {
        base.CreateDefaultButton();
        AddDefaultButton(new EditorButton(ButtonPredefines.SpinRight), Keys.Add);
        AddDefaultButton(new EditorButton(ButtonPredefines.SpinLeft), Keys.Subtract);
    }
}

public class MyButtonEdit : DevExpress.XtraEditors.ButtonEdit {
    static MyButtonEdit() {
        RepositoryItemMyButtonEdit.RegisterMyButtonEdit();
    }
    public override string EditorTypeName { get { return "MyButtonEdit"; } }
    // ...
}
vb
Public Class RepositoryItemMyButtonEdit
    Inherits RepositoryItemButtonEdit

    ' ...
    Public Shared Sub RegisterMyButtonEdit()
        ' ...
        EditorRegistrationInfo.Default.Editors.Add(New EditorClassInfo("MyButtonEdit", _ 
        GetType(MyButtonEdit), GetType(RepositoryItemMyButtonEdit), _ 
        GetType(ButtonEditViewInfo), New DevExpress.XtraEditors.Drawing.ButtonEditPainter(), _ 
        True, EditImageIndexes.ButtonEdit, _ 
        GetType(DevExpress.Accessibility.ButtonEditAccessible)))
    End Sub

    Private Sub AddDefaultButton(ByVal btn As EditorButton, ByVal keys As Keys)
        btn.IsLeft = True
        btn.Shortcut = New DevExpress.Utils.KeyShortcut(keys)
        btn.IsDefaultButton = True
        Buttons.Add(btn)
    End Sub

    Public Overrides Sub CreateDefaultButton()
        MyBase.CreateDefaultButton()
        AddDefaultButton(New EditorButton(ButtonPredefines.SpinRight), Keys.Add)
        AddDefaultButton(New EditorButton(ButtonPredefines.SpinLeft), Keys.Subtract)
    End Sub
End Class

Public Class MyButtonEdit
    Inherits DevExpress.XtraEditors.ButtonEdit

    Shared Sub New()
        RepositoryItemMyButtonEdit.RegisterMyButtonEdit()
    End Sub

    Public Overrides ReadOnly Property EditorTypeName() As String
        Get
            Return "MyButtonEdit"
        End Get
    End Property
End Class

The image below shows the result:

The following code snippets (auto-collected from DevExpress Examples) contain references to the IsDefaultButton property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-win-custom-button-in-lookup-property-editor/CS/EFCore/LookUpButtonEF/LookUpButtonEF.Win/Editors/MyLookupPropertyEditor.cs#L23

csharp
void MyLookupPropertyEditor_ButtonClick(object sender, ButtonPressedEventArgs e) {
    if (!e.Button.IsDefaultButton) {
        IObjectSpace objectSpace = Helper.Application.CreateObjectSpace(this.ObjectType);

winforms-custom-buttonedit-display-editvalue-on-button/CS/TestMyButtonEdit/RepositoryItemMyButtonEdit.cs#L53

csharp
EditorButton eb = new EditorButton(ButtonPredefines.Glyph);
eb.IsDefaultButton = true;
Buttons.Add(eb);

winforms-custom-buttonedit-display-editvalue-on-button/VB/TestMyButtonEdit/RepositoryItemMyButtonEdit.vb#L39

vb
Dim eb As New EditorButton(ButtonPredefines.Glyph)
eb.IsDefaultButton = True
Buttons.Add(eb)

See Also

Custom Editors

EditorButton Class

EditorButton Members

DevExpress.XtraEditors.Controls Namespace