开发者

How to forbid users to close the form? (MS VS C# 2010) [duplicate]

开发者 https://www.devze.com 2023-03-25 07:52 出处:网络
This question already has answers here: Closed 11 years ago. 开发者_JAVA技巧Possible Duplicate: How to Disable Alt + F4 closing form?
This question already has answers here: Closed 11 years ago.
开发者_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;
      }
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消