Click here to Skip to main content
Click here to Skip to main content

Tagged as

Disable the Close box on a form

, 18 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Disable the Close box on a form
If you want to prevent the user from closing your form until he has dealt with something really important, you can set
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 CreateParms getter:
protected override CreateParams CreateParams
            CreateParams parms = base.CreateParams;
            parms.ClassStyle |= 0x200;  // CS_NOCLOSE
            return parms;
  1. If you do this, all normal methods of closing the form become unavailable to the user. Use this only when it is really needed.
  2. Remember to provide some way to close the form (and test it!)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wales Wales
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?
Follow on   Google+

Comments and Discussions

GeneralMy vote of 4 PinmemberSanjay K. Gupta1-Jun-12 19:34 
QuestionNice tip PinmemberCIDev3-May-12 4:04 
GeneralReason for my vote of 5 I found it helpful. Hence voted 5. PinmemberProEnggSoft24-Feb-12 19:50 
GeneralThis is very helpfull. Thank you very much xD // Enable/Dis... PinmemberBen Pretorius4-Jul-11 23:41 
GeneralReason for my vote of 5 I liked it. Found it helpful and wor... PinmemberAll Time Programming4-Jul-11 21:50 
GeneralReason for my vote of 5 Good one i have used before works we... Pinmembercharles henington27-Jun-11 13:01 
GeneralHow to alternatively close the form after this? Or How to en... Pinmembermaxxon1517-Apr-11 6:33 
GeneralRe: You can't AFAIK re-enable the button (the CreateParms getter... PinmvpOriginalGriff17-Apr-11 22:09 
GeneralRe: You can't AFAIK re-enable the button (the CreateParms getter... PinmemberCIDev3-May-12 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 18 Feb 2012
Article Copyright 2010 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid