如何禁用ALT + F4关闭的形式?形式、ALT

由网友(流年带走了谁的物是人非)分享简介:什么是禁用的最好办法替代 + F4 在C#赢形式prevent从关闭的形式向用户?What is the best way to disable Alt + F4 in a c# win form to prevent the user from closing the form?我使用的一种形式弹出对话框显示进...

什么是禁用的最好办法替代 + F4 在C#赢形式prevent从关闭的形式向用户?

What is the best way to disable Alt + F4 in a c# win form to prevent the user from closing the form?

我使用的一种形式弹出对话框显示进度条,我不希望用户能够将其关闭。

I am using a form as a popup dialog to display a progress bar and I do not want the user to be able to close it.

推荐答案

这做这项工作:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;
}

编辑:在回答pix0rs关注 - 是的,你是正确的,你将无法以编程方式关闭该应用程序。但是,你可以简单地关闭窗体之前删除的事件处理程序form_closing事件:

In response to pix0rs concern - yes you are correct that you will not be able to programatically close the app. However, you can simply remove the event handler for the form_closing event before closing the form:

this.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Close();
阅读全文

相关推荐

最新文章