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
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?