可能重复:
如何禁用 Alt + F4 关闭表单?
请帮帮我。
如何制作仅从程序代码关闭的模态表单。当用户按下 Alt+F4 等时,我想防止表单关闭。
我正在使用 MS VS C# 2010。
您可以尝试覆盖 formClosing 事件。
只需进入 Visual Studio,选择程序的主窗体,在事件选项卡中的选项 (f4) 下查看。查找 FormClosing 并处理您的新代码。
e.Cancel = true;
^ 把它放在新的代码块中,你会阻止你的申请表在 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;
}
}
}