CheckBox has two or three states. This control in the Windows Forms platform provides a way for an option to be selected and deselected independently of other options. As with other controls, it can be manipulated in C# code for custom behaviors.
This C# tutorial shows how to use the CheckBox control from Windows Forms.

To get started, you must first add a CheckBox control to your Windows Form in the designer view in Visual Studio. Open the Toolbox pane and then find and double-click on the CheckBox icon. This will insert a CheckBox into your window. Next, you can add event handlers and change properties by right-clicking on the CheckBox and selecting Properties.
It is possible to set the CheckBox to allow three different states; these include an indeterminate state as well as checked and unchecked. The next screenshot shows what the indeterminate state looks like when it has been selected in the form; after, we see how you can determine what state the CheckBox is in.

Program that uses CheckState and Checked properties [C#]
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());
}
}
}One of the best things about Windows Forms is that it allows you to change a lot of the styles to suit your tastes. Please remember, though, that if you are a computer programmer your tastes might not match those of a professional designer. In this next screenshot, we see what the CheckBox looks like when I changed the CheckAlign property, and also the FlatStyle property.

Typically, the CheckBox control is not used as a key control that determines what happens on the Form. In other terms, the CheckBox state is read when a user performs an action on another control, such as a button that accepts the enclosing dialog window. However, the most useful event handler is probably the CheckChanged event handler, which will fire whenever the user clicks or changes the CheckBox. You can add the CheckChanged event handler by clicking on the lightning bolt and double-clicking on the CheckChanged name.

Although the CheckBox is useful control in the Windows Forms platform and the C# language, it is not often a major focus of applications. Instead, it is a small, supporting control; nevertheless, this article described various properties of the CheckBox, which may be useful for planning some programming tasks.
Windows Forms