In my recent project I faced a window closing issue caused by validation. My Windows form is validated. Whenever I click on “cancel button” or “close icon” of my window control I got stuck because the window didn’t close but was asking for input in atext box since it is validated.
This will cause a serious problem in real life applications. So the solution is as follows.
To show the demo I created a windows form application with validated text box.
Here I have a validated Text box, when I click on enter it focuses the text box with blinking red icon and asks for input.
It is what validation does, but when I click on close button (window control) it also behaves in the same way which is a show stopper, because the person wants to close the window but instead he asked for input.
So to solve this problem there is a simple method to follow.
Step 1: Select the window form and go to its properties.
Step 2: Here, under “Behavior” select the “AutoValidate” property and set it to “Disable”.