Checkboxes
The checkbox acts as a "toggle" control: if it's on, clicking it turns it off; if it's off, clicking it turns it on. Unlike the radio button, the operation of each checkbox on a form or group box is independent of all other checkboxes; changing the status of one does not affect other checkboxes.
The program can read or set the status of a checkbox with the Boolean Checked property (True is checked, False is unchecked).
Following is a checkbox demo. The form contains 6 checkboxes within a group box, named chkHobby1, chkHobby2, chkHobby3, chkHobby4, chkHobby5, and chkHobby6. The form also contains buttons named btnOK and btnExit, and a label called lblInfo. This is the form at design time:
The code behind the OK button is:
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim strInfo As String
strInfo = "Items selected: "
If chkHobby1.Checked Then strInfo &= chkHobby1.Text
If chkHobby2.Checked Then strInfo &= ", " & chkHobby2.Text
If chkHobby3.Checked Then strInfo &= ", " & chkHobby3.Text
If chkHobby4.Checked Then strInfo &= ", " & chkHobby4.Text
If chkHobby5.Checked Then strInfo &= ", " & chkHobby5.Text
If chkHobby6.Checked Then strInfo &= ", " & chkHobby6.Text
lblInfo.Text = strInfo
End Sub
Sample run:
Download the VB project code for the example above here.