Take the 2-minute tour ×

I have a modal dialog, and need to hide the Close (X) button, but I cannot use ControlBox = false, because I need to keep the Minimize and Maximize buttons.

I need to hide just Close button, is there any way to do that?

Thanks a lot!

Update: I had permission to disable it, which is simpler :) Thanks all!

share|improve this question
Could this be what yuo want: [Hide Close Button [X] of Win Forms in C#.NET](sameeramrutia.wordpress.com/2008/09/16/…) just googled: hide close button c#, second result here! =) –  Miguel Angelo Sep 4 '11 at 20:17
you are wrong, i do not want disable button, but HIDE it.. are u able to find a solution ? –  stefano m Sep 4 '11 at 20:21
Need is a strong word. Where is this requirement coming from? What is the actual requirement - that the user can't terminate the program, or that the UI "looks like it doesn't have a close button"? Because there are other ways around this, and you're going to be hard pressed to completely close off all of them (e.g. task manager, taskkill, possibly alt+f4, etc). I personally wouldn't work too hard at this, because unless you're re-skinning your whole app anyhow, it will be wasted effort, and break user expectations/continuity with other Windows programs. –  Merlyn Morgan-Graham Sep 4 '11 at 20:31
@Sayem it reveals this page, so don't be such a critic. –  Brian Graham Sep 4 '11 at 20:32
Scratch the minimize button off your list as well. Minimizing a modal dialog will automatically make it close. Necessarily so, it is the only window left that's still enabled. When you minimize it, there would not be any window left that can still get the focus so the user can't get back to your program. You are now in "does this still make sense?" territory. It doesn't. –  Hans Passant Sep 4 '11 at 21:04

5 Answers 5

up vote 42 down vote accepted

You can't hide it, but you can disable it by overriding the CreateParams property of the form.

private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
       CreateParams myCp = base.CreateParams;
       myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
       return myCp;

Source: http://www.codeproject.com/KB/cs/DisableClose.aspx

share|improve this answer
thanks, i found this solution, but we would like hide it, not just disable :( anywat thanks! –  stefano m Sep 4 '11 at 20:20
there isn't a way other than to design your form from scratch. –  Daniel A. White Sep 4 '11 at 20:21
yeah. better make your own form with your own controlbox without the close button then hide the parent form's control box. –  Bahamut Apr 27 '13 at 6:56

We can hide close button on form by setting this.ControlBox=false;

share|improve this answer
Did you read the question where he specified that that wasn't an option? –  Servy Nov 9 '12 at 20:40
Did a Google search and this SO QA was the top hit. And this answer was what I was looking for. Thank you Abhishek... –  Abel Apr 2 '13 at 18:39
That hides all of those sizing buttons. Not just the X. –  Rich Shealer Jan 15 at 19:50

Well, you can hide it, by removing the entire system menu:

private const int WS_SYSMENU = 0x80000;
protected override CreateParams CreateParams
        CreateParams cp = base.CreateParams;
        cp.Style &= ~WS_SYSMENU;
        return cp;

Of course, doing so removes the minimize and maximize buttons.

If you keep the system menu but remove the close item then the close button remains but is disabled.

The final alternative is to paint the non-client area yourself. That's pretty hard to get right.

share|improve this answer

If you really want to hide it, as in "not visible", then you will probably have to create a borderless form and draw the caption components yourself. VisualStyles library has the Windows Elements available. You would also have to add back in the functionality of re-sizing the form or moving the form by grabbing the caption bar. Not to mention the system menu in the corner.

In most cases, it's hard to justify having the "close" button not available, especially when you want a modal form with minimizing capabilities. Minimizing a modal form really makes no sense.

share|improve this answer

You can hide it using this.ControlBox=false

share|improve this answer

Your Answer


