- The CheckBox control is a small rectangle with a corresponding text displayed at the right side of it. This text works as a Label for the checkbox.
- When you want the user to have multiple options to choose from the existing list you use the CheckBox control.
- You can place a CheckBox control on the form by drag and drop it from the toolbox. The CheckBox control looks like as follows:
Properties of CheckBox Control
Some of the commonly used properties of CheckBox Control are listed below in the Table:
Events of CheckBox Control
Some of the commonly used events of CheckBox Control are listed below in the Table:
Methods of CheckBox Control
Some of the commonly used Methods of CheckBox Control are listed below in the Table:
Here is a simple example of CheckBox control. To understand the use of the CheckBox control follows the given steps:
- Add Two CheckBox controls and a TextBox control on the form from the toolbox.
- Now double click on CheckBox1 and add the following code in its code-window:
if (checkBox1.Checked == true)
textBox1.Text = “You clicked at Checkbox1”;
- In the above code the Checked property of the checkbox1 returns a Boolean value either True or false indicating whether the checkbox was selected or not. If true a then the text box will display the message ‘You clicked at Checkbox1’.
- Now double click on CheckBox2 and add the following code in its code-window:
if (checkBox2.Checked == true)
textBox1.Text = “You clicked at Checkbox2”;
- Now run the application using F5 key. This will generate a Form. Click on CheckBox1 this will display a text in the textbox as follows:
- Now when you click on the CheckBox2 you will see another message in the TextBox. You can also see that after clicking on the second check box, the first check box still remain selected. It is the advantage of the Checkbox control that it allows multiple selections at the same time.