For the complete documentation index, see llms.txt. This page is also available as Markdown.

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}";

Try on XnaFiddle.NET

CheckBox responding to Checked and Unchecked events by printing output

IsChecked

IsChecked is a nullable bool value.

Value
Details

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:

Try on XnaFiddle.NET

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:

Try on XnaFiddle.NET

CheckBox Width and Height

Default CheckBoxes have the following default values:

Variable
Value

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:

Try on XnaFiddle.NET

ComboBox with wrapped text

Last updated

Was this helpful?