How can I see and control when the user presses the X button in the upper right hand corner?
I'd like to bring up a msgbox that asks if the user really wants to quit. I notice a lot of programs do this. Is it possible to disable the X button at certain times?
The X button
Started by dirkfirst, Jul 14 2006 08:02 AM
3 replies to this topic
#1
Posted 14 July 2006 - 08:02 AM
|
|
|
#2
Guest_NeedHelp_*
Posted 17 July 2006 - 12:21 PM
Guest_NeedHelp_*
Click on your form and then click on the lightning bolt. It is one of those options, maybe close?
#3
Posted 17 July 2006 - 02:22 PM
Where? I do not see it.
#4
Posted 17 July 2006 - 06:42 PM
dirkfirst said:
How can I see and control when the user presses the X button in the upper right hand corner? I'd like to bring up a msgbox that asks if the user really wants to quit.
In your dialog class (the one you want to confirm closing) There is a FormClosing event that gets called before the closing happens. Here is an example:
private void MainApp_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure you want to close?", "Confirm Close", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
This is a very primitive C# example, but it works.
dirkfirst said:
I notice a lot of programs do this. Is it possible to disable the X button at certain times?
There are two ways to do this, the only one I can remember is the "control box" propery, set this to 'false' and it will disable all the buttons in the top right of the screen. There is a property for each of these individually, so you should be able to find a property for the exit button.
To disable and enable it during your code merely add this line to disable:
Form.Controlbox = false; (or form.controlbox.enabled = false;) i dont remember
and the obvious to re-enable it.


Sign In
Create Account


Back to top









