C# desktop app disable the close button
I am writing a C# 2010 desktop application. I would like to disable the close button on the windows form. I only want the user to exit the application by clicking the exit button on the application. Thus can you tell me how to disable the close button on the windows form application?
Sanjeeb LenkaPosted Jun 27, 2013, 3:20 PM
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;
}
}
or
you can follow this link
http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms
VulpesPosted Jun 27, 2013, 3:24 PM
1. Set the form's ControlBox property to false. However, this not only removes the X button, it all removes the Maximize and Minimize buttons as well.
2. You can capture the pressing of the X button in the Form's FormClosing event, tell the user that it can only be closed using the Exit button and then cancel the closure operation.
3. You can disable the X button (gray it out) by inserting the code which Sanjeeb posted in your Form class.