开发者_JAVA技巧Possible Duplicate:
How to Disable Alt + F4 closing form?
Help me pls.
How to make a modal form, that closes only from program code. I want to prevent form closing when user presses Alt+F4 etc.
I'm using MS VS C# 2010.
You could try to override the formClosing event.
Just go into Visual Studio, select your program's main form, look under options (f4) in the events tab. Look up FormClosing and handle your new code.
e.Cancel = true;
^ put that in the new code block and you'll prevent your application form closing on alt+f4
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// put your validation here.
if (validations)
{
// Display a MsgBox asking the user to continue or abort.
if(MessageBox.Show("message...?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
}
}
}
精彩评论