CheckBox control

  • 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:
CheckBox Control

Properties of CheckBox Control


Some of the commonly used properties of CheckBox Control are listed below in the Table:


CheckBox Control

Events of CheckBox Control


Some of the commonly used events of CheckBox Control are listed below in the Table:


CheckBox Control

Methods of CheckBox Control


Some of the commonly used Methods of CheckBox Control are listed below in the Table:


CheckBox Control

Example

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:
  • Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
    TextBox1.Text = "You clicked at Checkbox1"
    End If
    End Sub

  • In the above code the Checked property of the checkbox 1 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 CheckBox1 and add the following code in its code-window:
  • Private Sub CheckBox2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox2.CheckedChanged
    If CheckBox2.Checked = True Then
    TextBox1.Text = "You clicked at Checkbox2"
    End If
    End Sub

  • 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:
  • CheckBox Control

  • 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 ot allows multiple selection at the same time.
  • CheckBox Control