|
-
Dec 6th, 2003, 12:03 AM
#1
Thread Starter
Fanatic Member
Close button of form
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
-
Dec 6th, 2003, 12:31 AM
#2
Sleep mode
-
Dec 6th, 2003, 12:33 AM
#3
Frenzied Member
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)
Last edited by Memnoch1207; Dec 6th, 2003 at 12:40 AM.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Dec 6th, 2003, 12:39 AM
#4
Sleep mode
Originally posted by Memnoch1207
Set the ControlBox property of the form to false.
This will hide it !
-
Dec 9th, 2003, 01:36 AM
#5
Addicted Member
to disable close ("X") button of my form
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
-
Dec 9th, 2003, 12:00 PM
#6
Sleep mode
Re: to disable close ("X") button of my form
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
I know this will work , but some people prefer seeing the "X" button grayed out rather than handling the event after triggered .
-
Dec 11th, 2003, 11:15 AM
#7
Addicted Member
to disable close ("X") button of my form
Hi,
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.ControlBox = False
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|