Is there any event that fire when the value of the textbox change from a peace of code and when the textbox is validated or lost the focus and the event don’t fire on the key press,because I have a lot of calculation and It’s not possible to do it on every key press
Share
There’s no event that will fulfill your requirement of being raised when the textbox’s value is changed programmatically through code, but not when text is typed into it by the user. The
TextChangedevent is going to be raised either way (this is fairly intuitive—the text value is changing, and the computer doesn’t know or care what is responsible for changing it). As the documentation for this event indicates:If you need to run custom validation logic when you add text to your textbox in code, you will need to invoke whatever method contains the validation logic yourself. Extract it into a separate method, which you call from the
Validating/Validatedevent handler and from all of the places in your code where you set the textbox’sTextproperty.As a supplement to the other answers that have already been posted, I strongly recommend using either the
Validating(if you want to be able to cancel the validation) orValidatedevents to handle the textbox losing focus, rather than the somewhat more obviously namedLostFocusevent.