windowsforms-devexpress-dot-xtraeditors-92da0b06.md
The text editor that displays buttons in the edit box.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXLicenseWinFormsEditors]
public class ButtonEdit :
TextEdit
<DXLicenseWinFormsEditors>
Public Class ButtonEdit
Inherits TextEdit
The following members return ButtonEdit objects:
The ButtonEdit control is a text editor (a TextEdit descendant) that allows you to display one or more buttons in the edit box.
You can embed a ButtonEdit control in a container control (for instance, GridControl, TreeList, RibbonControl) to display/edit data in this container’s cell or item. Use a RepositoryItemButtonEdit object to create an in-place editor.
Use the ButtonEdit.Text or ButtonEdit.EditValue property to access or set a standalone editor’s text.
buttonEdit1.EditValue = "Abc";
ButtonEdit1.EditValue = "Abc"
The ButtonEdit.Text and ButtonEdit.EditValue properties allow you to bind an editor to a data source.
buttonEdit1.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.carsBindingSource, "Description", true));
ButtonEdit1.DataBindings.Add(New System.Windows.Forms.Binding("EditValue", Me.CarsBindingSource, "Description", True))
Handle the ButtonEdit.EditValueChanged/ButtonEdit.Properties.EditValueChanged or inherited TextChanged event to respond to text changes.
Use the ButtonEdit.Properties object to access and customize the control’s settings.
The main settings include:
Use the Properties.Buttons collection to add buttons to standalone editors.
Each button (an EditorButton object) exposes properties to specify image options (ImageOptions), button kind (Kind), caption (Caption), tooltip (ToolTip, SuperTip), enabled state, appearance settings, etc.
Handle the following events to perform actions when a user clicks an embedded button:
You can enable the RepositoryItemButtonEdit.AllowButtonNavigation option to allow users to focus editor buttons with the keyboard.
The following code creates a ButtonEdit control and places it onto a panel:
The code changes the button collection as follows:
The example subscribes to the ButtonEdit.ButtonClick event to respond to button clicks.
ButtonEdit btnEdit1 = new ButtonEdit();
btnEdit1.Width = 100;
btnEdit1.Properties.Buttons[0].Kind = ButtonPredefines.OK;
btnEdit1.Properties.Buttons.Add(new EditorButton(ButtonPredefines.Delete));
panel1.Controls.Add(btnEdit1);
btnEdit1.ButtonClick += BtnEdit1_ButtonClick;
private void BtnEdit1_ButtonClick(object sender, ButtonPressedEventArgs e) {
ButtonEdit editor = sender as ButtonEdit;
if(e.Button.Kind == ButtonPredefines.OK) {
//...
}
if (e.Button.Kind == ButtonPredefines.Delete) {
//...
}
}
Dim btnEdit1 As ButtonEdit = New ButtonEdit()
btnEdit1.Width = 100
btnEdit1.Properties.Buttons(0).Kind = ButtonPredefines.OK
btnEdit1.Properties.Buttons.Add(New EditorButton(ButtonPredefines.Delete))
Panel1.Controls.Add(btnEdit1)
AddHandler btnEdit1.ButtonClick, AddressOf BtnEdit1_ButtonClick
Private Sub BtnEdit1_ButtonClick(sender As Object, e As ButtonPressedEventArgs)
Dim editor As ButtonEdit = TryCast(sender, ButtonEdit)
If e.Button.Kind = ButtonPredefines.OK Then
'...
End If
If e.Button.Kind = ButtonPredefines.Delete Then
'...
End If
End Sub
The following example embeds an in-place ButtonEdit editor (a RepositoryItemButtonEdit object) into a Data Grid’s “Description” column.
The example creates two buttons (Undo and Copy) for the editor and handles the RepositoryItemButtonEdit.ButtonClick event to perform actions when a user clicks any of these buttons.
RepositoryItemButtonEdit inplaceButtonEdit = new RepositoryItemButtonEdit();
inplaceButtonEdit.Buttons.Clear();
//Undo Button
EditorButton undoButton = new EditorButton(ButtonPredefines.Undo);
undoButton.Enabled = false;
//Copy Button
EditorButton copyButton = new EditorButton(ButtonPredefines.Glyph);
copyButton.Caption = "Copy";
copyButton.ImageOptions.SvgImage = global::WindowsFormsApplication2.Properties.Resources.copy;
copyButton.ImageOptions.SvgImageSize = new Size(16, 16);
inplaceButtonEdit.Buttons.Add(undoButton);
inplaceButtonEdit.Buttons.Add(copyButton);
inplaceButtonEdit.ButtonClick += InplaceButtonEdit_ButtonClick;
inplaceButtonEdit.EditValueChanged += InplaceButtonEdit_EditValueChanged;
gridView1.Columns["Description"].ColumnEdit = inplaceButtonEdit;
gridView1.GridControl.RepositoryItems.Add(inplaceButtonEdit);
private void InplaceButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e) {
ButtonEdit editor = sender as ButtonEdit;
if (e.Button.Kind == ButtonPredefines.Undo) {
editor.Undo();
}
if (e.Button.Kind == ButtonPredefines.Glyph && e.Button.Caption == "Copy") {
editor.SelectAll();
editor.Copy();
}
}
private void InplaceButtonEdit_EditValueChanged(object sender, EventArgs e) {
ButtonEdit editor = sender as ButtonEdit;
if (editor.Properties.Buttons.Count == 0) return;
EditorButton undoButton = editor.Properties.Buttons[0];
if ( undoButton.Kind == ButtonPredefines.Undo) {
undoButton.Enabled = editor.CanUndo;
}
}
Dim inplaceButtonEdit As RepositoryItemButtonEdit = New RepositoryItemButtonEdit()
inplaceButtonEdit.Buttons.Clear()
'Undo Button
Dim undoButton As EditorButton = New EditorButton(ButtonPredefines.Undo)
undoButton.Enabled = False
'Copy Button
Dim copyButton As EditorButton = New EditorButton(ButtonPredefines.Glyph)
copyButton.Caption = "Copy"
copyButton.ImageOptions.SvgImage = Global.WindowsFormsApplication7.My.Resources.copy
copyButton.ImageOptions.SvgImageSize = New Size(16, 16)
inplaceButtonEdit.Buttons.Add(undoButton)
inplaceButtonEdit.Buttons.Add(copyButton)
AddHandler inplaceButtonEdit.ButtonClick, AddressOf InplaceButtonEdit_ButtonClick
AddHandler inplaceButtonEdit.EditValueChanged, AddressOf InplaceButtonEdit_EditValueChanged
GridView1.Columns("Description").ColumnEdit = inplaceButtonEdit
GridView1.GridControl.RepositoryItems.Add(inplaceButtonEdit)
Private Sub InplaceButtonEdit_ButtonClick(ByVal sender As Object, ByVal e As ButtonPressedEventArgs)
Dim editor As ButtonEdit = TryCast(sender, ButtonEdit)
If e.Button.Kind = ButtonPredefines.Undo Then
editor.Undo()
End If
If e.Button.Kind = ButtonPredefines.Glyph AndAlso e.Button.Caption = "Copy" Then
editor.SelectAll()
editor.Copy()
End If
End Sub
Private Sub InplaceButtonEdit_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim editor As ButtonEdit = TryCast(sender, ButtonEdit)
If editor.Properties.Buttons.Count = 0 Then
Return
End If
Dim undoButton As EditorButton = editor.Properties.Buttons(0)
If undoButton.Kind = ButtonPredefines.Undo Then
undoButton.Enabled = editor.CanUndo
End If
End Sub
using System;
using System.Drawing;
using DevExpress.XtraEditors.Controls;
// Creates a button and sets its Kind property to 'ButtonPredefines.Glyph' to display a custom image.
EditorButton customButton = new EditorButton(ButtonPredefines.Glyph);
// Specifies an SVG image.
customButton.ImageOptions.SvgImage = svgImageCollection1[0];
// Sets the image size.
customButton.ImageOptions.SvgImageSize = new Size(16, 16);
// Adds the button to the Button Editor's 'Properties.Buttons' collection.
buttonEdit1.Properties.Buttons.Add(customButton);
Imports System
Imports System.Drawing
Imports DevExpress.XtraEditors.Controls
' Creates a button and sets its Kind property to 'ButtonPredefines.Glyph' to display a custom image.
Dim customButton As New EditorButton(ButtonPredefines.Glyph)
' Specifies an SVG image.
customButton.ImageOptions.SvgImage = svgImageCollection1(0)
' Sets the image size.
customButton.ImageOptions.SvgImageSize = New Size(16, 16)
' Adds the button to the Button Editor's 'Properties.Buttons' collection.
buttonEdit1.Properties.Buttons.Add(customButton)
The following screenshots shows the result:
DevExpress controls support regular and super tooltips. Enable the ShowToolTips option to display tooltips when the mouse pointer hovers over the control.
Customize Regular Tooltip Text
Use the following properties of the target control to specify regular tooltip text and title:
|
API
|
Description
| | --- | --- | |
|
Specifies tooltip text. You can use line breaks in regular tooltips.
| |
|
Specifies whether to parse HTML tags in text.
| |
|
Specifies the tooltip title. If you do not specify tooltip text, the tooltip is not displayed even if you specify the title.
|
The following code snippet specifies tooltip text and title for a TextEdit editor:
public Form1() {
InitializeComponent();
textEdit1.ShowToolTips = true;
textEdit1.ToolTipTitle = "Name";
textEdit1.ToolTip = "Please enter your name";
}
Public Sub New()
InitializeComponent()
textEdit1.ShowToolTips = True
textEdit1.ToolTipTitle = "Name"
textEdit1.ToolTip = "Please enter your name"
End Sub
Private Sub ToolTipController1_BeforeShow(ByVal sender As Object, ByVal e As ToolTipControllerShowEventArgs)
Dim controller As ToolTipController = TryCast(sender, ToolTipController)
If e.ToolTip = textEdit1.ToolTip Then
e.ImageOptions.SvgImage = (TryCast(controller.ImageList, SvgImageCollection))("personalCard")
End If
End Sub
Assign an Image to Regular Tooltips
Use the control’s ToolTipIconType property to assign a predefined icon. The ToolTipController.IconSize property specifies icon size.
Assign a custom image as follows:
Note
The ToolTipIconType property has priority over e.ImageOptions. If you assign a custom image, set ToolTipIconType to None.
The following code snippet assigns a custom image to the TextEdit tooltip:
Note
textEdit1, toolTipController1, and svgImageCollection1 were created at runtime.
public Form1() {
InitializeComponent();
textEdit1.ShowToolTips = true;
textEdit1.ToolTipTitle = "Name";
textEdit1.ToolTip = "Please enter your name";
textEdit1.ToolTipController = toolTipController1;
toolTipController1.ImageList = svgImageCollection1;
toolTipController1.BeforeShow += ToolTipController1_BeforeShow;
}
private void ToolTipController1_BeforeShow(object sender, ToolTipControllerShowEventArgs e) {
ToolTipController controller = sender as ToolTipController;
if (e.ToolTip == textEdit1.ToolTip)
e.ImageOptions.SvgImage = (controller.ImageList as SvgImageCollection)["personalCard"];
}
Public Sub New()
InitializeComponent()
textEdit1.ShowToolTips = True
textEdit1.ToolTipTitle = "Name"
textEdit1.ToolTip = "Please enter your name"
textEdit1.ToolTipController = toolTipController1
toolTipController1.ImageList = svgImageCollection1
AddHandler toolTipController1.BeforeShow, AddressOf ToolTipController1_BeforeShow
End Sub
Private Sub ToolTipController1_BeforeShow(ByVal sender As Object, ByVal e As ToolTipControllerShowEventArgs)
Dim controller As ToolTipController = TryCast(sender, ToolTipController)
If e.ToolTip = textEdit1.ToolTip Then
e.ImageOptions.SvgImage = (TryCast(controller.ImageList, SvgImageCollection))("personalCard")
End If
End Sub
Display a Super Tooltip
Use the control’s SuperTip property to assign a super tooltip. If you wish to use HTML tags in a super tooltip, enable the SuperToolTip.AllowHtmlText property.
Setting the ToolTipController.ToolTipType property to SuperTip converts existing regular tooltips to super tooltips.
Tip
Read the following help topic for information on how to customize super tooltips: Hints and Tooltips.
Show 55 items
Object MarshalByRefObject Component Control DevExpress.XtraEditors.XtraControl ControlBase BaseControl BaseEdit TextEdit ButtonEdit HyperLinkEdit
ResourcesPopupCheckedListBoxControl
StorageBindedImageComboBoxEdit
See Also