Order of events when switching Winform controls
I have a "Leave" event on a text box and a "SelectedValueChanged" even开发者_StackOverflow社区 on a list box. Going from the text box to the list box, will one fire before the other? Or, will they fire simultaneously?
ListBox.Enter has to fire before it can see a change in the selected value. Which implies that the TextBox.Leave fires first. Events can never fire simultaneously, these are events that run on the UI thread, one at a time.
Leave event will fire before SelectedValueChanged
They do not fire simultaneously.
Have the "Output" or the "Immediate Window" open in your development (depending on your debugging options), and then from your code:
private void textBox1_Leave(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Text Leave");
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("ListBox SelectedValueChanged");
}
In your Output or Immediate window, you should see the "Text Leave" message before the "ListBox SelectedValueChanged" message when your TextBox has the focus and you select an item in the ListBox next.
精彩评论