[英]Remove the Close button in the program's title bar
Goal: 目标:
Don't want the user to use the X mark (upper right of the program's screen) to exit the program. 不希望用户使用X标记(程序屏幕的右上角)退出程序。
Problem: 问题:
Don't know how to remove that icon that allows user to exit the program? 不知道如何删除允许用户退出程序的图标?
You can set the ControlBox
property to false
if you don't want this to display. 如果不希望显示
ControlBox
属性,可以将其设置为false
。 This will also remove the minimize and maximize buttons, mind you. 请注意,这也会删除最小化和最大化按钮。
I would also ask you to consider why you want to remove this button. 我还要求您考虑为什么要删除此按钮。 Sometimes it makes more sense to override the
OnFormClosing
method and optionally set Cancel
to true
under certain conditions (eg, e.CloseReason == CloseReason.UserClosing
). 有时候覆盖
OnFormClosing
方法更有意义,并且在某些条件下可选择将Cancel
设置为true
(例如, e.CloseReason == CloseReason.UserClosing
)。
myForm.ControlBox = false;
Apparently I have to have at least 30 characters in my post, so I will say that I am assuming WinForms since you do not specify yourself. 显然我的帖子中必须至少有30个字符,所以我会说我假设WinForms,因为你没有指定自己。 Also note that setting this property to false will remove the minimize and maximize buttons as well.
另请注意,将此属性设置为false也会删除最小化和最大化按钮。
myform.ControlBox = false;
这对我来说
This guy seems to have figured it out: 这家伙似乎已经弄清楚了:
http://blogs.msdn.com/b/atosah/archive/2007/05/18/disable-close-x-button-in-winforms-using-c.aspx http://blogs.msdn.com/b/atosah/archive/2007/05/18/disable-close-x-button-in-winforms-using-c.aspx
我用它,它为我工作
this.ControlBox = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.