Based on the latest information added to your question, skip to the end of my answer.
This is what you need to set to false: Form.ControlBox Property
BUT, you will lose the minimize and maximize buttons, as well as the application menu (top left).
Alternatively, override OnClose and set Cancel to true (C # example):
protected override void OnFormClosing(FormClosingEventArgs e) { if (e.CloseReason != CloseReason.WindowsShutDown && e.CloseReason != CloseReason.ApplicationExitCall) { e.Cancel = true; } base.OnFormClosing(e); }
If none of these solutions is acceptable and you should only disable the close button, you can go to the pinvoke / createparams route:
How to disable the close button from a window form using a .NET application
This is the jdm code version of VB version:
Private Const CP_NOCLOSE_BUTTON As Integer = &H200 Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams Get Dim myCp As CreateParams = MyBase.CreateParams myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON Return myCp End Get End Property
Philip wallace
source share