If you want to prevent the user from closing your form until he has dealt with something really important, you can set
Form.ControlBox=false
but this also removes the Min, Max, and system menu from the form as well.
You cannot (it seems) remove just the Close box, but you can disable it, and it alone. To disable and grey out the Close box, override the CreateParams
getter:
protected override CreateParams CreateParams
{
get
{
CreateParams parms = base.CreateParams;
parms.ClassStyle |= 0x200;
return parms;
}
}
WARNING:
- If you do this, all normal methods of closing the form become unavailable to the user. Use this only when it is really needed.
- Remember to provide some way to close the form (and test it!)
History
2016-07-20 Typo fixed - thanks Brisingr Aerowing!
2010-01-26 Original version