Im in my first C# and GUI class and im wondering how i stop an event from executing. In my case i have a button and a textbox, if the button is clicked when there is invalid input in the textbox the button event should stop executing.
Loading
Im in my first C# and GUI class and im wondering how i stop an event from executing. In my case i have a button and a textbox, if the button is clicked when there is invalid input in the textbox the button event should stop executing.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Feb 9, 2023, 4:06 AM
Hello David,
You can use the
returnstatement to stop the execution of the event handler method.Example:
Thanks
Naimish Makwana
David OestPosted Feb 10, 2023, 4:13 PM
Thank you so much for the simple and fast answer.
Vishal JoshiPosted Feb 9, 2023, 5:59 AM
Hello
Please try the below way to complete the requirement.
In properties choose “Events” and under focus double-click on “validating”. after select validation method you need to write method like below code sample:
Please check below article for more details.
https://www.c-sharpcorner.com/blogs/how-to-use-validation-in-windows-form-application
Thanks