How to disable the Win Form’s Close Button ?

Disable the Win Form’s Close Button using C#

Here is the simple way to disable the Form’s close button. Just copy the following code in your code behind. Then run the form, surely the close button would be disabled.

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

That's it...


1 comment:

- shεncu said...

Your blog has been very useful with my development.

Thanx a lot!