如何禁用ALT + F4关闭的形式? [英] How to Disable Alt + F4 closing form?

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

问题描述

什么是禁用的最好办法<大骨节病>替代 + <大骨节病> 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();

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

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