I need to disable just the close button (minimize and maximize should be allowed) temporarily.
Every solution I\'ve tried disables all the buttons
You can't hide it, but you can disable it:
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
return myCp;
}
}
Source: http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms
If you absolutely need to hide it, the only way to do it is to create a borderless form, then draw your own minimize and maximize buttons. Here is an article on how to do this: http://www.codeproject.com/Articles/42223/Easy-Customize-Title-Bar
Before considering either of these solutions, you should maybe rethink why you need to do this. Depending on what you are trying to do, there is probably a much better way to present the UI to the user other than taking away the familiar 'X' close button.