how to put an .net application in system tray when minimized?

bugBurger picture bugBurger · Sep 16, 2008 · Viewed 12.4k times · Source

can anyone please suggest a good code example of vb.net/c# code to put the application in system tray when minized.

Answer

Phillip Wells picture Phillip Wells · Sep 16, 2008

Add a NotifyIcon control to your form, then use the following code:

    private void frm_main_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized)
        {
           this.ShowInTaskbar = false;
           this.Hide();
           notifyIcon1.Visible = true;
        }
    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
        this.ShowInTaskbar = true;
        notifyIcon1.Visible = false;
    }

You may not need to set the ShowInTaskbar property.