1. Lesson 6 of 8 Visual Basic Programming
1 of 2
Lesson 6: CheckBoxes and RadioButtons
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2020 May 12
CheckBox Control
The CheckBoxes should be used when users are allowed to choose
several items from a group of choices. Look at the form given below.
The code segment for the button Display is given below.
Dim s As String = ""
If CheckBox1.CheckState = CheckState.Checked Then
s += CheckBox1.Text + " "
End If
If CheckBox2.CheckState = CheckState.Checked Then
s += CheckBox2.Text + " "
End If
If CheckBox3.CheckState = CheckState.Checked Then
s += CheckBox3.Text + " "
End If
If CheckBox4.CheckState = CheckState.Checked Then
2. Lesson 6 of 8 Visual Basic Programming
2 of 2
s += CheckBox4.Text + " "
End If
MessageBox.Show (s)
RadioButton Control
The RadioButtons should be used when users are allowed to choose
only one item from a group of choices. Look at the form given below.
The code segment for the button Display is given below.
Dim s As String = ""
If RadioButton1.Checked = True Then
s = RadioButton1.Text
ElseIf RadioButton2.Checked = True Then
s = RadioButton2.Text
ElseIf RadioButton3.Checked = True Then
s = RadioButton3.Text
ElseIf RadioButton4.Checked = True Then
s = RadioButton4.Text
End If
MessageBox.Show (s)