我可以使用C#禁用表单的“关闭”按钮吗? [英] Can I disable the 'close' button of a form using C#?

查看:160
本文介绍了我可以使用C#禁用表单的“关闭”按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用表单中的关闭按钮,如下图所示? (下图显示 MessageBox 窗口)

How can I disable the close button of a form like in the image below? (the image below show a MessageBox window)

上面生成 MessageBox 由我!我想禁用普通表单的关闭按钮。

The MessageBox above was generated by me! I want to disable the close button of a normal form.

推荐答案

您处理关闭事件(而不是表格的封闭事件。

You handle the Closing event (and not the Closed event) of the Form.

然后你使用e.CloseReason来决定你是否真的想要阻止它(UserClose)(TaskManager Close) 。

And then you use e.CloseReason to decide if you really want to block it (UserClose) or not (TaskManager Close).

此外,还有一个小例子代码项目上禁用表单上的关闭按钮。

Also, there is small example Disabling Close Button on Forms on codeproject.

这篇关于我可以使用C#禁用表单的“关闭”按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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