Home
C#.WinForms
CheckBox Example
Updated Oct 9, 2022
Dot Net Perls
CheckBox. This control has 2 or 3 states. It provides a way for an option to be selected and deselected independently of other options.
Getting started. Add a CheckBox control to your Windows Form in the designer view in Visual Studio. To use the CheckBox, add a Load event handler on the form.
Form
RadioButton
CheckState. It is possible to set the CheckBox to allow three states. These include an indeterminate state as well as checked and unchecked.
Tip You can add event handlers and change properties by right-clicking on the CheckBox and selecting Properties.
MessageBox.Show
using System; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Acquire the state of the CheckBox. CheckState state = checkBox1.CheckState; // Demonstrate how the CheckBox can be switched upon. switch (state) { case CheckState.Checked: case CheckState.Indeterminate: case CheckState.Unchecked: { MessageBox.Show(state.ToString()); break; } } // Tell if the box is checked. MessageBox.Show(checkBox1.Checked.ToString()); } } }
CheckChanged. Typically, the CheckBox control is used alongside other controls. The CheckBox state is read when a user performs an action on another control, such as a button.
However The most useful event is probably CheckChanged—this event fires when the user clicks or changes the CheckBox.
And You can add the CheckChanged event handler by clicking on the lightning bolt and double-clicking on the CheckChanged name.
Summary. The CheckBox is useful control in Windows Forms. But it is not often a major focus of applications. It is instead a small, supporting control used with other controls.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Oct 9, 2022 (edit link).
Home
Changes
© 2007-2025 Sam Allen