Disabling Windows Buttons: Minimize,Restore,Close
-
Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.
-
Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.
Put all code that show the message box and eventually cancels the closing operation into the event handler for the
FormClosing
event and inside the buttonClick
event handler simply call theClose
method of your form.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.
About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use:
e.Cancel = true;
this also stops it from closing with the F4 key, so you can do like so: first, define the event:this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
and then in the event do something like this:void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; }
And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007 -
About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use:
e.Cancel = true;
this also stops it from closing with the F4 key, so you can do like so: first, define the event:this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
and then in the event do something like this:void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; }
And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007 -
About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use:
e.Cancel = true;
this also stops it from closing with the F4 key, so you can do like so: first, define the event:this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
and then in the event do something like this:void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; }
And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007I just tried it out, it is amazing, thankyou very much. Except I don't understand the:
this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
VC# EE just gave me a load of errors on that, and I don't quite know what it's doing anyway. Well, thanks for the great help.
-
I just tried it out, it is amazing, thankyou very much. Except I don't understand the:
this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
VC# EE just gave me a load of errors on that, and I don't quite know what it's doing anyway. Well, thanks for the great help.
Can you please say what the errors are?