Originally Posted by
woodsprite
Hello all,
I would like to disable use of the windows form ControlBox "X" or close button with out losing the minimize or maximize buttons. Setting the ControlBox = false removes all three options.
I've tried trapping in the Form.Closing event and it ignores all attempts to abort the cancel and closes the form anyway.
If anyone has any suggestions on how I can either disable the "X" or close button of the form ControlBox or prevent the form from closing in the Form.Closing event I would greatly appreciate it.
overide the Read Only Property CreateParams
in VB
Code:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim CS_NOCLOSE As Integer = Int32.Parse("200", Globalization.NumberStyles.HexNumber)
Dim cp As CreateParams = MyBase.CreateParams
cp.ClassStyle = CS_NOCLOSE
Return cp
End Get
End Property
in C#
Code:
protected override CreateParams CreateParams
{
get
{
const int CS_NOCLOSE = 0x200;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_NOCLOSE;
return cp;
}
}