I need to disable close ("X") button of my form . .how to do this? in VB6 I knew there is an API function for doing this .. how about in VB.NET? please advise
many thanks in advance
Regards
Winan
Printable View
I need to disable close ("X") button of my form . .how to do this? in VB6 I knew there is an API function for doing this .. how about in VB.NET? please advise
many thanks in advance
Regards
Winan
Setting the ControlBox property of the form to false will remove all 3 buttons (Maximize, Minimize and Close)
This code will just disable the close button
VB Code:
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer Public Const MF_BYPOSITION = &H400& Public Const MF_DISABLED = &H2& Dim hMenu As Integer, nCount As Integer 'Get handle to system menu hMenu = GetSystemMenu(Me.Handle.ToInt32, 0) 'Get number of items in menu nCount = GetMenuItemCount(hMenu) 'Remove last item from system menu (last item is ’Close’) Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION) 'Redraw menu DrawMenuBar(Me.Handle.ToInt32)
This will hide it ! ;)Quote:
Originally posted by Memnoch1207
Set the ControlBox property of the form to false.
Hi,
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub
Have a nice day
I know this will work , but some people prefer seeing the "X" button grayed out rather than handling the event after triggered . :pQuote:
Originally posted by yulyos
Hi,
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub
Have a nice day
Hi,
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.ControlBox = False
End Sub