Minimize your .NET Application to System Tray

Just come across this requirement today.

1. Drag a NotifyIcon from your toolbox.

2. The ‘Text’ value is what it shows when you move hover your icon.

3. Link your ‘Icon’ property to an .ico

4. Add this event handler to your form.

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

5. Add this event handler to your NotifyIcon

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

For adding right click context menu to your system tray icon, see here.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s