How to automatically start a program in the tray - Digital Tool Factory blog How to automatically start a program in the tray - Digital Tool Factory blog

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.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog

Tags:

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.