Why does my TextChanged textbox get fired after entering "only" one character in the textbox?

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 starts. How to make the program wait until I finish entering the entire line for the field (for example, Name ex: James).

+5
source share
2 answers

If you want to determine when the user has finished entering, you can catch the vacation event instead - this fires when the focus is lost in this text field - that is, the user clicks outside the text field:

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

If you are working with VS2019, there is a correlation between the TextChanged event and the Focus Leave event. You should have a TextChanged event, then when searching for events and detecting focus, select β€œLeave”, after which a pop-up window will appear with the TextChanged event for the same object as the focus event that you select. This will add a Leave Event to the scope of Form1, but it will not generate code in the scope of Form1, as with the usual double-click on a TextBox. This you must create yourself. This article has helped me do this part. Later this afternoon. I was wrong. You do not need to select the TextChanged event. It was the only one available in the drop-down list at that time. I had to add both events to the scope of form1 again, since I removed the TextChanged event, and manuallu added the Focus_Leave event, and then returned to add the TextChanged event. I am experimenting here. But when I deleted them both and entered the events in the form1.design file again, it became possible to choose the right one. I had another error, but now they are in sync again. This is all the code that is generated behind the scenes with MS VS, which makes it difficult to change this area. And, of course, they advise you not to change it, but what will you do if you make such a mistake, don’t start again, immerse yourself and continue to learn how they do what they do.

0
source

Source: https://habr.com/ru/post/1481483/


All Articles