How to disable close button in top-right form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to mimic sql server 2000 console. It has disabled close button on top
right console root form. How to make it?

Thank you in advance.
 
Set a form global variable in the form's declaration section (above the load
event):

Public closetest As Boolean = True

If you have a close button that you want to allow you to get out of the
form, change the status of closetest to false. Then, in the closing event
of the form:

If closetest = True Then

e.Cancel = True

End If

HTH,

Bernie Yaeger
 
add this to the form:

Protected Overrides ReadOnly Property CreateParams() _
As System.Windows.Forms.CreateParams
Get
Const CS_NOCLOSE As Integer = &H200
Dim Params As CreateParams = MyBase.CreateParams
Params.ClassStyle = Params.ClassStyle Or CS_NOCLOSE
Return Params
End Get
End Property

CAUTION: You wont be able to close the form from anywhere except the task
manager (or if you are in debug mode, using the stop button in the IDE).

hope that helps..
Imran.
 
* "=?Utf-8?B?RGVhc3k=?= said:
I want to mimic sql server 2000 console. It has disabled close button on top
right console root form. How to make it?

Add this to your form:

\\\
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Int32 = &H8
Const CS_NOCLOSE As Int32 = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
///

Alternatively you can remove the according menu items from the system
menu using p/invoke.
 
Back
Top