disable the close button of a .net windows form

This tip demonstrates how to disable the close button of a .NET Windows Form.

During construction and creation of the Form object, .Net would use the default creation parameters available in base class CreateParams property. In fact, CreateParams property is available in Forms.Control class. In our form class (derived from System.Windows.Forms.Form) override this property and modify the creation flags. For disabling the Close button use 0x200 to modify the ClassStyle member of the CreateParams.


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;
     }
}


Happy coding
Ashu Chauhan
email: mail2ashu.c@gmauil.com

By Ashu Chauhan   Popularity  (1591 Views)