Why my textbox TextChanged event gets fired after

2019-02-17 22:09发布

问题:

private void NameVal_TextChanged(object sender, EventArgs e)
    {
        String text = NameVal.Text;

    }

As soon as I enter the first letter of my Name this program gets executed . How do I make the program wait until I finish entering the whole string for the field (such as Name ex: James) is entered.

回答1:

If you want to determine when the user has finished typing, you can catch the leave event instead - this is fired when the focus is lost on that text box - ie the user clicks outside of the textbox:

private void NameVal_Leave(object sender, EventArgs e)
{
    //Do your stuff
    String text = NameVal.Text;
}