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?

25 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.

    • David Rokni says:

      This will only disable the X close button:

      public partial class Form1 : Form
      {
      private const int CS_NOCLOSE = 0x200;
      protected override CreateParams CreateParams
      {
      get
      {
      CreateParams mdiCp = base.CreateParams;
      mdiCp.ClassStyle = mdiCp.ClassStyle | CS_NOCLOSE;

      return mdiCp;
      }
      }

      public Form1()
      {
      InitializeComponent();
      }

      }

  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 = 0x200;
    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!!!

  17. gaurish says:

    thanks man …..thanks

  18. Udara says:

    Thank you very much………..

  19. Aditya says:

    Thank you very much Ji that solve my all problem chak de

  20. True, there are comedians that cuss a lot, but you got
    to earn that right before you do that. No matter what your field, it
    helps to know what you’re good at, but it also helps to recognize what others are good at.
    He represented his homeland in four Olympics and is a three-time indoor world champ in the 1500 meters.

  21. To maneuver your ships, just left button phone on the spot.
    zynga poker chips at no cost When you be a part of Poker.
    Mail, yet others and enable the hacker to have remote device of the account
    and it is contents.

  22. Johnd82 says:

    Good post. I study something more challenging on completely different blogs everyday. It is going to all the time be stimulating to learn content material from different writers and practice somewhat one thing from their store. I ecfdaakfekdf

  23. beto says:

    excellent… best regards

  24. […] Disable Close button in Windows form | Codelicious – Sep 07, 2007  · 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 … […]

Leave a comment