简体   繁体   English

删除程序标题栏中的“关闭”按钮

[英]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.ControlBox = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM