• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

over load close function button?

Is there a way to overload the close button that is on the top right corner or most windows programs.  I have an application that uses the system tray.  I want to make it so that when the user clicks on the close button it doesn't really close the program.  I want it to just minimize or hide it.  but i still want it running until the user right clicks on the system tray item and selects exit.
1 Solution
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If (UnloadMode = 0) Then Cancel = 1
    Visible = False
End Sub
You need to put code in the QueryUnload Event of your form.  There is a variable that gets passed into this routine when a user tries to close the form.. UNLOADMODE...

You can look a UNLOADMODE and do whatever you want...  You can also set the CANCEL to TRUE and the program will not terminate.

UNLOADMODE can be one of the following and you can test for it:

vbFormControlMenu      0      The user chose the Close command from the Control menu on the form.
vbFormCode      1      The Unload statement is invoked from code.
vbAppWindows      2      The current Microsoft Windows operating environment session is ending.
vbAppTaskManager      3      The Microsoft Windows Task Manager is closing the application.
vbFormMDIForm      4      An MDI child form is closing because the MDI form is closing.

ueihpAuthor Commented:
Thanks!  =)

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now