articles

Home / DeveloperSection / Articles / How should use CheckBox Control in VB.Net

How should use CheckBox Control in VB.Net

How should use CheckBox Control in VB.Net

Pushpendra Singh 20254 12-Dec-2010

A Checkbox control is used to display a check_box.

Where 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 options.

If a checkbox is selected, a check (a tick mark) appears indicating a selection.

How to use the CheckBox Control

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

How should use CheckBox Control in VB.Net

Drag and drop two more CheckBox.

How should use 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 

How should use CheckBox Control in VB.Net

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

How should use CheckBox Control in VB.Net

CheckBox Control Properties

CheckState:     The 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:

How should use 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:

How should use CheckBox Control in VB.Net

Now checkbox will show a 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 the run, time checkbox back_color will be changed.

Output:

How should use CheckBox Control in VB.Net

 You should also read this Article - Using ReportViewer in WinForms C#


Updated 04-Mar-2020

Leave Comment

Comments

Liked By