Results 1 to 5 of 5

Thread: Few Questions

  1. #1

    Thread Starter
    Lively Member Goat Spirit's Avatar
    Join Date
    Aug 2006
    Location
    Goat Heaven
    Posts
    105

    Few Questions

    1.How can I change the behavior of the X button on a window.
    2.If I do the above what code would I need to make it minimize to the tray.
    3.Once in tray. how can I make it so that if you right click, it will bring up a little menu like on other apps. Thanks.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Few Questions

    The 'x' button click fires the Form_QueryUnload event where you can check the UnloadMode for it closing because of being clicked. Then cancel the unload and code to minimize to the system tray. Code for the minimize to tray can be found with a search on VBF
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Few Questions

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     Cancel = 1 'prevents from closing
    3.         'your continue code
    4. End Sub

  4. #4
    Addicted Member
    Join Date
    Jun 2006
    Location
    Virac
    Posts
    129

    Re: Few Questions

    try this one!

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     Me.WindowState = vbMinimized
    3.     Cancel = True
    4. End Sub

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Few Questions

    The problem with just added minimize function to the QueryUnload event is that regardles of how you are closing your application, the only thing that will ever happen is that it will be minimized. You need a way to both minimize the form it the X is clicked, but, also to completely close the application if so desired. The way to do that is to check the UnloadMode. That will tell HOW the window is being closed.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. If UnloadMode = vbFormControlMenu Then 'they hit the X
    3.    Me.WindowState = vbMinimized
    4.    Cancel = True
    5. End If
    6. End Sub
    7.  
    8. Private Sub cmdExit_Click()
    9. Unload Me
    10. 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
  •  



Click Here to Expand Forum to Full Width