Minimize application to System Tray

A quick snippet to show how to minimize an application to the Windows System Tray using a NotifyIcon. Set the NotifyIcon text to be whatever you want displayed when you hover over it in the System Tray and be sure to set the Icon property too, else nothing will get displayed! Then add the following in the form_resize event:

private void wfMain_Resize(object sender, EventArgs e)
{
    if (FormWindowState.Minimized == WindowState)
        Hide();
}

And to restore it to it’s former state. simply add the following in the DoubleClick event of your NotifyIcon:

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
    this.Show();
    WindowState = FormWindowState.Normal;
}
Advertisements