Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling the close form button 1

Status
Not open for further replies.

MikeCt

Programmer
Nov 6, 2001
44
US
Hi
On a form there are the 3 buttons that control the form
MinButton,MaxButton, and the close form button.

Is there a way to disable the close form button at runtime?
What event is triggered when this button is Pressed?

Thanks Mike
 

If you are talking VB 6 - check Form_QueryUnload event:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, _
    UnloadMode As Integer)

If UnloadMode = 0 Then
    Cancel = 1
End If

End Sub

Have fun.

---- Andy
 
Just to add to that:

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
 
All that said, I would not recommend disabling the closing of a form in this manner, any more than I would recommend reversing the accelerator and brake on a car. There are ways to get what you want without trying to redesign the way the Windows operating system works.
 
Then there is the api way...

thread222-1232760

thread222-523899

althogh, the x still looks like it should work but it doesn't

Then here is a way to see if the mouse is over the x by strongm thread222-1160525



Good Luck
 
All that said, I would not recommend disabling the closing of a form in this manner, any more than I would recommend reversing the accelerator and brake on a car. There are ways to get what you want without trying to redesign the way the Windows operating system works.

Some applications are designed to take the user through a serious of steps with forward and back options and possibly an abort option. A partial process may need rolled back. In cases like that I can see not allowing the “X” option. You aren’t redesigning Windows, you are designing an application.
 
Some applications are designed to take the user through a serious of steps with forward and back options and possibly an abort option. A partial process may need rolled back. In cases like that I can see not allowing the "X" option. You aren't redesigning Windows, you are designing an application.
I think the point was that in an application that you suggested, "The Windows norm" would to not offer a control box in possibly a modal window rather than just disabling the close window "X".

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top