Click Event not fired

  • Thread starter Thread starter David Kelly
  • Start date Start date
D

David Kelly

I am noticing a strange behaviour with the button Click event.

A simple test case - a form with a textbox and a button. Attach the
following two handlers.

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave
MsgBox("leave")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MsgBox("click")
End Sub

When the user is in the textbox and clicks the button then the leave
event fires (as expected) but no click event????

If I do not handle the leave event then the click event fires.

Any ideas?
 
* (e-mail address removed) (David Kelly) scripsit:
I am noticing a strange behaviour with the button Click event.

A simple test case - a form with a textbox and a button. Attach the
following two handlers.

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave
MsgBox("leave")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MsgBox("click")
End Sub

When the user is in the textbox and clicks the button then the leave
event fires (as expected) but no click event????

Make sure the button's name is 'Button1'. Your code should work.
 
The Messagebox call in the leave event sets the focus to the Messagebox.
Hence, no click event for the button is raised.
 
yEaH rIgHt said:
The Messagebox call in the leave event sets the focus to the Messagebox.
Hence, no click event for the button is raised.

Thanks for that. I tried the test again just renaming some labels instead
of a messagebox and sure enough all the events fire.

Quite a trap. I am not sure if it is a bug or correct behaviour but very
easy to get yourself caught by it.
 
Back
Top