winformstextboxuser-inputtextchanged

Why my textbox TextChanged event gets fired after I enter "only" one character in my text box?


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.


Solution

  • 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;
    }