如何禁用 Alt + F4 关闭表单? [英] How to Disable Alt + F4 closing form?

查看:37
本文介绍了如何禁用 Alt + F4 关闭表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 c# win 表单中禁用 Alt + F4 以防止用户关闭表单的最佳方法是什么?

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_closure 事件的事件处理程序:

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();

这篇关于如何禁用 Alt + F4 关闭表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆