Here is a short example showing how the click events are executed on the check box:
Private Sub CheckBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseDown Dim a As Integer = 1 End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Dim a As Integer = 2 End Sub Private Sub CheckBox1_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click Dim a As Integer = 3 End Sub Private Sub CheckBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseClick Dim a As Integer = 4 End Sub Private Sub CheckBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseUp Dim a As Integer = 5 End Sub
If you set breakpoints in each of the ads, you will notice that only the MouseDown event is fired before CheckChanged. This means that if you want to see if the user clicked this check box, you will need to fire the event in the CheckBox.MouseDown element. Keep in mind that each time the user clicks this checkbox, he will trigger this event, even if they pull the mouse out of it while holding it, and SHOULD NOT update the event with the modified scan. It just means that you will need to fire the next event in Sub MouseUp to clear the flag.
One way to handle this would be something like this:
Private blIsUserClick As Boolean Private Sub CheckBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseDown blIsUserClick = True End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged If blIsUserClick Then 'Is a user click event Else 'Not a user click event End If End Sub Private Sub CheckBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseUp blIsUserClick = False End Sub
source share