windowsforms-devexpress-dot-xtraeditors-21b343b8.md
Allows an end user to select among the unchecked, checked, and indeterminate state (optional). Multiple check boxes can be combined into a radio group.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DefaultBindingPropertyEx("CheckState")]
[DXLicenseWinFormsEditors]
public class CheckEdit :
BaseCheckEdit
<DefaultBindingPropertyEx("CheckState")>
<DXLicenseWinFormsEditors>
Public Class CheckEdit
Inherits BaseCheckEdit
The check box supports the following states:
To specify the check box state, use the following properties:
View Example: Change the check box state by clicking exactly on the checkbox (glyph)
To respond to check state changes, handle the CheckEdit.CheckStateChanged, CheckEdit.CheckedChanged, or BaseEdit.EditValueChanged event.
If the check box is bound to a data source field, ensure that the types of the ValueChecked, ValueUnchecked, and ValueGrayed values match the field type. The example below shows how to set these properties to byte values:
checkEdit1.Properties.ValueChecked = (byte)2;
checkEdit1.Properties.ValueGrayed = (byte)1;
checkEdit1.Properties.ValueUnchecked = (byte)0;
CheckEdit1.Properties.ValueChecked = CType(2, Byte)
CheckEdit1.Properties.ValueGrayed = CType(1, Byte)
CheckEdit1.Properties.ValueUnchecked = CType(0, Byte)
Use the Properties.CheckBoxOptions.Style (see RepositoryItemCheckEdit.CheckBoxOptions) property to specify what the check box looks like:
Default — the style is specified by the Properties.CheckStyle property.
Svg[Glyph] — a vector glyph scaled without loss of quality according to the current DPI setting.
Checkbox — a regular check box.
Radio — a button in a radio group (a group of mutually exclusive options).
Custom — any custom glyph specified with Properties.ImageOptions (see RepositoryItemCheckEdit.ImageOptions).
Check boxes are rendered according to the currently applied skin and palette.
To specify the caption, use the following properties:
To specify whether the glyph is aligned to the left or right relative to the caption, use the Properties.GlyphAlignment property (see BaseRepositoryItemCheckEdit.GlyphAlignment).
The caption is hidden if the glyph is aligned to the center.
If an Svg[Glyph] style is applied, you can specify the vector glyph size and colors using the Properties.CheckBoxOptions properties (see RepositoryItemCheckEdit.CheckBoxOptions):
SvgColorUnchecked , SvgColorChecked , SvgColorGrayed — the colors used to paint vector glyphs in the corresponding states. Vector glyphs are colored according to the current skin and palette.
SvgImageSize — the size of vector glyphs. The default glyph size is 18x18 pixels on a 100% DPI screen. Vector glyphs are automatically scaled according to the DPI setting without loss of quality.
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.
This example demonstrates how to programmatically create two check editors, initialize their properties and assign the same handler for their CheckEdit.CheckedChanged events. The created check editors will be used to control the visibility and availability of a standard button control. The example implies that the button is already placed onto a form.
Changing the check state of the first check editor affects both the button’s visibility and the second check editor’s availability. The second check editor specifies the availability of the button for end-users.
The image below displays the example application.
using DevExpress.XtraEditors;
using DevExpress.Utils;
private void CreateCheckEditors() {
// creating and initializing the first check editor
CheckEdit chEdit1 = new CheckEdit();
chEdit1.Properties.Caption = "Hide Button";
chEdit1.Name = "chEdit1";
chEdit1.Location = new System.Drawing.Point(6, 35);
chEdit1.Width = 100;
// setting the editor's check state depending upon the button's visibility
if (!(button1.Visible)) chEdit1.Checked = true;
// assigning a handler for the CheckChanged event of the first check editor
chEdit1.CheckedChanged += new EventHandler(CheckedChanged);
this.Controls.Add((Control)chEdit1);
// creating and initializing the second check editor
CheckEdit chEdit2 = new CheckEdit();
chEdit2.Properties.Caption = "Disable Button";
chEdit2.Name = "chEdit2";
chEdit2.Location = new System.Drawing.Point(6, 55);
chEdit2.Width = 100;
// setting the editor's check state depending upon the button's availability
if (!(button1.Enabled)) chEdit2.Checked = true;
if (!(button1.Visible)) chEdit2.Enabled = false;
// assigning a handler for the CheckChanged event of the second check editor
chEdit2.CheckedChanged += new EventHandler(CheckedChanged);
this.Controls.Add((Control)chEdit2);
}
private void CheckedChanged(object sender, System.EventArgs e) {
CheckEdit edit = sender as CheckEdit;
switch (edit.Checked) {
case true:
if (edit == GetCheckEdit("chEdit1")){
// hiding the button
button1.Visible = false;
// disabling the second check editor
GetCheckEdit("chEdit2").Enabled = false;
}
else if (edit == GetCheckEdit("chEdit2")){
// enabling the button
button1.Enabled = false;
}
break;
case false:
if (edit == GetCheckEdit("chEdit1")){
// showing the button
button1.Visible = true;
// enabling the second check editor
GetCheckEdit("chEdit2").Enabled = true;
}
else if (edit == GetCheckEdit("chEdit2")){
// disabling the button
button1.Enabled = true;
}
break;
}
}
private CheckEdit GetCheckEdit(string editName){
foreach(Control control in this.Controls){
if ((control is CheckEdit) && (control.Name == editName))
return control as CheckEdit;
}
return null;
}
Imports DevExpress.XtraEditors
Imports DevExpress.Utils
Private Sub CreateCheckEditors()
' creating and initializing the first check editor
Dim ChEdit1 As New CheckEdit()
ChEdit1.Properties.Caption = "Hide Button"
ChEdit1.Name = "ChEdit1"
ChEdit1.Location = New System.Drawing.Point(6, 35)
ChEdit1.Width = 100
' setting the editor's check state depending upon the button's visibility
If Not Button1.Visible Then ChEdit1.Checked = True
' assigning a handler for the CheckChanged event of the first check editor
AddHandler ChEdit1.CheckedChanged, AddressOf CheckedChanged
Me.Controls.Add(CType(ChEdit1, Control))
' creating and initializing the second check editor
Dim ChEdit2 As New CheckEdit()
ChEdit2.Properties.Caption = "Disable Button"
ChEdit2.Name = "ChEdit2"
ChEdit2.Location = New System.Drawing.Point(6, 55)
ChEdit2.Width = 100
' setting the editor's check state depending upon the button's availability
If Not Button1.Enabled Then ChEdit2.Checked = True
If Not Button1.Visible Then ChEdit2.Enabled = False
' assigning a handler for the CheckChanged event of the second check editor
AddHandler ChEdit2.CheckedChanged, AddressOf CheckedChanged
Me.Controls.Add(CType(ChEdit2, Control))
End Sub
Private Sub CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Edit As CheckEdit = CType(sender, CheckEdit)
Select Case Edit.Checked
Case True
If Edit Is GetCheckEdit("ChEdit1") Then
' hiding the button
Button1.Visible = False
' disabling the second check editor
GetCheckEdit("ChEdit2").Enabled = False
ElseIf Edit Is GetCheckEdit("ChEdit2") Then
' enabling the button
Button1.Enabled = False
End If
Case False
If Edit Is GetCheckEdit("ChEdit1") Then
' showing the button
Button1.Visible = True
' enabling the second check editor
GetCheckEdit("ChEdit2").Enabled = True
ElseIf Edit Is GetCheckEdit("chEdit2") Then
' disabling the button
Button1.Enabled = True
End If
End Select
End Sub
Private Function GetCheckEdit(ByVal editName As String) As CheckEdit
Dim Control As Control
For Each Control In Me.Controls
If TypeOf Control Is CheckEdit And Control.Name = editName Then
Return CType(Control, CheckEdit)
EndIf
Next
Return Nothing
End Function
Object MarshalByRefObject Component Control DevExpress.XtraEditors.XtraControl ControlBase BaseControl BaseEdit BaseCheckEdit CheckEdit
See Also