CheckBox
This control has 2 or 3 states. It provides a way for an option to be selected and deselected independently of other options.
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.
CheckState
It is possible to set the CheckBox
to allow three states. These include an indeterminate state as well as checked and unchecked.
CheckBox
and selecting Properties.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.
CheckChanged
—this event fires when the user clicks or changes the CheckBox
.CheckChanged
event handler by clicking on the lightning bolt and double-clicking on the CheckChanged
name.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.