The Checkbox control is used to display a check box. The Checkbox control gives us an option to select, say, yes/no or true/false. A checkbox is clicked to select and clicked again to deselect some option. When a checkbox is selected, a check (a tick mark) appears indicating a selection.

How use the CheckBox Control

Drag and drop three checkbox and a Button from toolbox on window form.

CheckBox Control in VB.Net

Drag and drop two more CheckBox.

CheckBox Control in VB.Net

Code:

Public Class Form4
 
 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        'display checkbox value when checkbox1 is checked
        Label3.Text = "Selected Language is   " + CheckBox1.Text
    End Sub
 
  Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        'display checkbox value when checkbox2 is checked
        Label3.Text = "Selected Language is   " + CheckBox2.Text
    End Sub
 
  Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        'display checkbox value when checkbox3 is checked
        Label3.Text = "Selected Language is   " + CheckBox3.Text
    End Sub
End Class

 

Run the project

 

CheckBox Control in VB.Net

When you select any language then CheckedChanged event of CheckBox will fire and selected language will show in Label.

CheckBox Control in VB.Net

CheckBox Control Properties

CheckState:     Default value is Unchecked. Set it to True if you want a check to appear when form executed.

For Example:

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'check will appear at run time
        CheckBox1.CheckState = CheckState.Checked
    End Sub

 

Output:

CheckBox Control in VB.Net

Appearance: Default value is Normal. Set the value to Button if you want the CheckBox to be displayed as a Button.

For Example:

'set checkbox appearance as button
  Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckBox1.Appearance = Appearance.Button
        CheckBox2.Appearance = Appearance.Button
        CheckBox3.Appearance = Appearance.Button
 End Sub

 

Output:

CheckBox Control in VB.Net

Now checkbox will show as button. But checkbox Behaviour will not change.

BackColor:

You can change the BackColor of CheckBox for example

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' change the backcolor of checkbox
        CheckBox1.BackColor = Color.BurlyWood
        CheckBox2.BackColor = Color.BurlyWood
        CheckBox3.BackColor = Color.BurlyWood
    End Sub

At run time checkbox backcolor will be changed.

Output:

CheckBox Control in VB.Net

 

  Modified On Mar-22-2018 07:18:04 AM

Leave Comment