Skip to main content

EditorButton Class

An editor button displayed in a ButtonEdit control or its descendant.

Namespace: DevExpress.XtraEditors.Controls

Assembly: DevExpress.XtraEditors.v25.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public class EditorButton :
    IDisposable,
    ICaptionSupport,
    ISupportCommandBinding,
    ISupportAppearanceObjectPropertiesFilter

The following members return EditorButton objects:

Remarks

ButtonEdit and all its descendants can display edit buttons within the edit box. The editor stores its buttons within the RepositoryItemButtonEdit.Buttons collection. You can add, remove, and rearrange edit buttons. Button settings allow you to specify the caption, glyph, appearance, shortcut, visibility, tooltip, etc.

Button Click

Edit buttons do not have their own click/press events. Handle the RepositoryItemButtonEdit.ButtonClick and RepositoryItemButtonEdit.ButtonPressed events to respond to button clicks.

Button Image and Caption

The Kind property specifies the button’s image. You can choose from over 20 predefined icons or specify a custom image. Set the Kind property to Glyph and use the ImageOptions property to display a custom image within the button.

The Caption property specifies the button’s text. The button can display the text together with a custom image only, which is not centered (EditorButton.ImageOptions.Location).

Edit Button with Image and Caption - WinForms Data Editors | DevExpress

using DevExpress.Utils.Svg;
using DevExpress.XtraEditors;
using DevExpress.Utils.Taskbar;
using DevExpress.XtraEditors.Controls;

EditorButton button = buttonEdit1.Properties.Buttons[0];
button.Caption = "Add Employee";
button.Kind = ButtonPredefines.Glyph;
button.ImageOptions.Location = ImageLocation.MiddleLeft;
button.ImageOptions.SvgImage = SvgImage.FromFile("custom-image.svg");

Wrap Button Caption

The Button Editor stretches its edit buttons if the TextEditStyle property is set to TextEditStyles.HideTextEditor. Disable the Button Editor’s Properties.AutoHeight option, specify the height, and set the button’s Appearance.TextOptions.WordWrap property to Wrap to break the long text and wrap it onto the next line.

Edit Button - Wrap Caption, WinForms Data Editors | DevExpress

Example

The following code snippet creates a ButtonEdit control, customizes its buttons, and places the editor onto the form:

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace DXApplication {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();

            // Create a `ButtonEdit` and add it to the form.
            ButtonEdit btnEdit1 = new ButtonEdit() {
                Width = 200
            };

            // Configure the default (first) button as an OK button.
            btnEdit1.Properties.Buttons[0].Kind = ButtonPredefines.OK;

            // Add an additional button and treat it as a Delete action.
            btnEdit1.Properties.Buttons.Add(new EditorButton(ButtonPredefines.Delete));

            // Add the editor to the form's controls collection.
            this.Controls.Add(btnEdit1);

            // Handle button clicks.
            btnEdit1.ButtonClick += BtnEdit1_ButtonClick;
        }
        void BtnEdit1_ButtonClick(object sender, ButtonPressedEventArgs e) {
            ButtonEdit editor = sender as ButtonEdit;
            if (e.Button.Kind == ButtonPredefines.OK) {
                // OK button pressed.
                //...
            }
            if (e.Button.Kind == ButtonPredefines.Delete) {
                // Delete button pressed.
                //...
            }
        }
    }
}

Inheritance

See Also