How not to close the window
-
I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.
-
I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.
-
I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.
Just Do This !!!
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please Fill Details"); e.Cancel = true; } else { MessageBox.Show("Thanks You !!!"); } }
cheers, Abhijit Read My Latest Article : IIS 7.0 and Deploying Asp.Net WebSites on IIS 7.0
-
I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.
Check out the ErrorProvider[^] class/component.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog)