Whenever a user clicks a Win Forms CheckBox control, the Click event occurs. You can program your application to perform some action depending upon the state of the check box.
To respond to CheckBox clicks
[Visual Basic] Private Sub Check1_Click() ' The CheckBox control's Text property changes each time the ' control is clicked, indicating a checked or unchecked state. If CheckBox1.Checked = True Then CheckBox1.Text = "Checked" Else CheckBox1.Text = "Unchecked" End If End Sub [C#] [MC++]
Note If the user attempts to double-click the check box control, each click will be processed separately; that is, the check box control does not support the double-click event.
Note When the AutoCheck property is True (the default), the CheckBox is automatically checked or unchecked when it is clicked. Otherwise, you must manually set the Checked property when the Click event occurs.
You can also use the CheckBox control to determine a course of action.
To determine a course of action
[Visual Basic] Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As SystemEventArgs) Select Case CheckBox1.CheckState Case CheckState.Checked ' Code for checked state. Case CheckState.Unchecked ' Code for unchecked state. Case CheckState.Indeterminate ' Code for indeterminate state. End Select End Sub [C#] [MC++]
Note When the ThreeState property is set to True, the Checked property returns True for both CheckState.Checked and CheckState.Indeterminate.