Click Event not fired

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?
 
H

Herfried K. Wagner [MVP]

* (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.
 
Y

yEaH rIgHt

The Messagebox call in the leave event sets the focus to the Messagebox.
Hence, no click event for the button is raised.
 
D

David Kelly

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top