How to automatically start a program in the tray

The Problem: There is no way to start a program minimized in the system tray

The Cause: The correct event is the Shown event, which is not intuitive (to me anyway).

The Solution: Just add in the following code:

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

private void MyForm_Load(object sender, EventArgs e)
{
this.Hide();
}
private void MyForm_Shown(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
Hide();
}

and you’re done!  You can then the start the program and it will automatically minimnize itself to the tray.

Popularity: 1% [?]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Posterous
  • Tumblr
  • Twitter

Leave a Reply