colinramsay.co.uk

Winforms Minimize to System Tray

19 May 2006

Best article I've seen on this is at developer.com. When you minimize your application, it actually fires a resize event on the form, so you can attach code to the resize event to handle this:

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

You add a NotifyIcon control to your form, and that creates the little icon on the system tray. There's a doubleclick event for that, and just handle it with this code:

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

And there you go. Thanks to developer.com.

Feedback or questions on this post? Create an issue on GitHub.