Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the Close button in the program's title bar

Tags:

c#

Goal:
Don't want the user to use the X mark (upper right of the program's screen) to exit the program.

Problem:
Don't know how to remove that icon that allows user to exit the program?

like image 622
What'sUP Avatar asked Feb 21 '11 21:02

What'sUP


People also ask

How to hide window Close button?

e. Cancel = true; This will prevent the window from closing. This has the same effect as hiding the close button.

Which button on the title bar is used to close the application?

The Close button is at the far right end of the title bar. It looks like a box with an X in it. You can click the Close button to close a window or exit an application.


2 Answers

You can set the ControlBox property to false if you don't want this to display. 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 (e.g., e.CloseReason == CloseReason.UserClosing).

like image 98
Dan Tao Avatar answered Oct 06 '22 00:10

Dan Tao


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. Also note that setting this property to false will remove the minimize and maximize buttons as well.

like image 34
Ed S. Avatar answered Oct 06 '22 00:10

Ed S.