C# Disable Or Hide Close Button(X) in Windows Form
This examples show how to hide/disable close button(X) in C#. To achieve this, we must override the CreateParams method in Form class.
Disable Close Button:
//Disable close button private const int CP_DISABLE_CLOSE_BUTTON = 0x200; protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ClassStyle = cp.ClassStyle | CP_DISABLE_CLOSE_BUTTON; return cp; } }
Remove The Entire System Menu:
//remove the entire system menu: private const int WS_SYSMENU = 0x80000; protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style &= ~WS_SYSMENU; return cp; } }
Thanks for sharing…
If you keep the system menu but remove the close item then the close button remains but is disabled.
thank you worked for me
thank for your post,
How to use this code with C++ winform.
Thank you very Much
Good! I have been seeking for this for over an hour! Works just fine, thank you!