Monday, May 10, 2010

how to minimize a c# .net windows application to system tray

First you need to add a NotifyIcon (ie, object notifyicon1) to your form, set the default Visible property to be false.


Add a Form_Resize event handler to the form.

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

 

Then add an event handler to the NotifyIcon (usually double click) with this code:

 

this.Visible = true;

notifyIcon1.Visible = false;

 

This article from Microsoft is also helpful: http://code.msdn.microsoft.com/TheNotifyIconExample

 

Will talk about minimizing native win32 app into tray next time.

 

0 comments: