C# CheckBox: Windows FormsThis C# tutorial shows how to use the CheckBox control from Windows Forms.
has 2 or 3 states. This control 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.
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 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.
C# program that uses CheckState and Checked properties
public partial class Form1 : Form
// Acquire the state of the CheckBox.
CheckState state = checkBox1.CheckState;
// Demonstrate how the CheckBox can be switched upon.
// Tell if the box is checked.
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 that if you are a computer programmer your tastes might not match those of a professional designer.
Next: In this screenshot, we see what the CheckBox looks like when I changed the CheckAlign property, and also the FlatStyle property.
CheckChanged. Typically, the CheckBox control is not used as a key control that determines what happens on the Form. The CheckBox state is read when a user performs an action on another control, such as a button.
the most useful event is probably CheckChanged. It fires when 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.Event
The CheckBox is useful control in the Windows Forms platform and the C# language. But it is not often a major focus of applications. It is instead a small, supporting control used with other controls.
Review: We described various properties of the CheckBox, which may be useful for planning some programming tasks.
© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.