How to hide only the Close (x) button?


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!

This question is tagged with c# winforms

~ Asked on 2011-09-04 20:09:40

The Best Answer is


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;


~ Answered on 2011-09-04 20:10:52


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

Note that this hides all of those sizing buttons. Not just the X. In some cases that may be fine.

~ Answered on 2012-11-09 20:20:53

Most Viewed Questions: