How can I disable a close button which is on upper right corner of a form as show in the attached file?
Printable View
How can I disable a close button which is on upper right corner of a form as show in the attached file?
You can't directly.
Most people just trap it in the Query_Unload event handler.
I'm not familiar with Query_Unload but here is how to trap a number of close events:
Code:Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
MsgBox "The user chose the Close command (the ""X"") from the Control menu on the form."
Case vbFormCode
MsgBox "The Unload statement is invoked from code."
Case vbAppWindows
MsgBox "The current Microsoft Windows operating environment session is ending."
Case vbAppTaskManager
MsgBox "The Microsoft Windows Task Manager is closing the application."
Case vbFormMDIForm
MsgBox "An MDI child form is closing because the MDI form is closing."
Case vbFormOwner
MsgBox "A form is closing because its owner is closing."
End Select
End Sub
just add Cancel= 1 in the case statement you want to disable
Is this what you are looking for?
http://www.codeguru.com/vb/gen/vb_fo...icle.php/c3031
Edit
There is one more simpler way to do it...
Paste this in the form code
and paste this in a moduleCode:Private Sub Form_Load()
Temp = DisableCloseButton(Form1) = False ' where Form1 is the name of your form
End Sub
Code:Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Const MF_BYPOSITION = &H400&
Public Function DisableCloseButton(frm As Form) As Boolean
Dim lHndSysMenu As Long
Dim lAns1 As Long, lAns2 As Long
lHndSysMenu = GetSystemMenu(frm.Hwnd, 0)
lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
End Function
We have FAQ code as well as mine and many others code which is the same or similar to koolsids. The Search page is your friend :)
LOL, damn this is an old post of mine:
http://www.vbforums.com/showpost.php...71&postcount=2
Thanks. Can I disable Maximise button and Close button like in the followingQuote:
Originally Posted by RobDog888
attached file:
Yes, just set the MaxButton property of the form to False.