CheckBox
Introduction
The CheckBox control provides the ability to display a true/false state and allows the user to toggle the state through clicking.
Code Example: Adding a CheckBox
// Initialize
var checkBox = new CheckBox();
checkBox.AddToRoot();
checkBox.X = 50;
checkBox.Y = 50;
checkBox.Text = "Checkbox";
checkBox.Checked += (_,_) => checkBox.Text = $"IsChecked:{checkBox.IsChecked}";
checkBox.Unchecked += (_, _) => checkBox.Text = $"IsChecked:{checkBox.IsChecked}";
IsChecked
IsChecked is a nullable bool value.
true
CheckBox is checked
false
CheckBox is not checked
null
CheckBox is in an indeterminate state
The following code creates three checkboxes each set to one of the three IsChecked values:
Three State CheckBox (IsThreeState)
By default, a CheckBox only cycles between Checked and Unchecked when clicked. Setting IsThreeState to true allows the user to cycle through all three states by clicking.
When IsThreeState is true, clicking the CheckBox follows this cycle: Unchecked -> Checked -> Indeterminate -> Unchecked
The following code creates a CheckBox that supports three states:
CheckBox Width and Height
Default CheckBoxes have the following default values:
Width
128
WidthUnits
Absolute
Height
32
HeightUnits
Absolute
The text within the CheckBox draws and wraps according to the bounds of the CheckBox. In other words, longer text results in line wrapping, as show in the following code block:

Last updated
Was this helpful?

