user2376123
user2376123

Reputation: 3

Why is the button click event not fired after textbox leave event?

I have text box with leave event

    private void textBox1_Leave(object sender, EventArgs e)
    {
        MessageBox.Show("Leave");
    }

and button with click event

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Click");
    } 

When I enter text in textbox and click the button the leave event fires but click event does not.

How do I fire the click event without invoking button1_Click in the leave event?

Upvotes: 0

Views: 1700

Answers (1)

Dmitry
Dmitry

Reputation: 14059

Simply replace MessageBox.Show with Console.WriteLine in the textBox1_Leave and you will see the button's click event. In other words, it seems that user interaction in the Leave event breaks events chain, because of the focus was captured by MessageBox.

Upvotes: 2

Related Questions