Search code examples
vb.netsystray

Hide a form to the system tray


I'm posting this here since it took a lot of time for me to understand how the whole thing works when trying to hide a form in the systray.

My question basically was: How can I hide a windows form running operations to the system tray?

CFP.


Solution

  • The first step is to show the from that you will need to hide. Make sure you don't make it Modal.

    Dim F as New MyForm
    Form.Show()
    

    Then, create a notification icon, and make associate the following with its click function:

    Me.Visible = Not Me.Visible
    

    Careful though. If you first showed the form using ShowDialog, then setting Visible = False will close the form and destroy it (which can get nasty if you were using a separate thread which communicated with the form, for example).