Disable Close button in Windows form

To disable that little close button in your Windows form, either you can set the ControlBox field in Properties window to False or or add this two line in the contructor:

this.ControlBox = false;

Same goes for Maximize and Minimize boxes. Set it using Properties window or add these lines:


this.MaximizeBox = false;
this.MinimizeBox = false;

Simple, huh?

16 thoughts on “Disable Close button in Windows form

  1. Bob says:

    if you disable the control box you automatically lose the icon, minimize and maximize buttons.

  2. ixi says:

    simple but incorrect
    check http://www.codeproject.com/KB/cs/DisableClose.aspx
    for a working solution

  3. Franz says:

    Thank you!!! that small works miracles.. the code for making the close inactive.. thank you

    private const int
    CP_NOCLOSE_BUTTON = 0×200;
    protected override CreateParams CreateParams
    {
    get
    {
    CreateParams myCp = base.CreateParams;
    myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
    return myCp;
    }
    }

  4. Sireesha says:

    Many Thanks for your answer

  5. Snattan says:

    Thank you! Excellent snippet!

  6. pradip says:

    great.. thank you.

  7. chat2learn says:

    Here you can find a perfect solution for this issue. I had the same problem and I fixed it.

    http://www.php24hours.com/c-sharp-how-to-disable-the-close-button-t164.html

  8. aryaa says:

    its realy good thanks dud……

  9. Rohit More says:

    Ohhh Heartily Thank you Very Much… :)

  10. qnthe says:

    this is realy good thank you so much

  11. Prafull says:

    thank you very much!!! its really good

  12. Sapna says:

    Thats right..
    this code has very great work
    thanks for it.

  13. sushil kumar mishra says:

    I am very happy to get this code

  14. Vamshi says:

    Can we disable these buttons during runtime?

  15. manoj jaiswal says:

    i want know only about cancel button only… other (maximize , minimize) should be visible.. while cancel button should be disable..

    thanks

  16. PePe says:

    SILENCE WHINERS!!!
    The controlbox = false/true works fine!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.