I followed the commonly-linked tip for reducing an application to the system tray : http://www.developer.com/net/csharp/article.php/3336751 Now it works, but there is still a problem : my application is shown when it starts ; I want it to start directly in the systray. I tried to minimize and hide it in the Load event, but it does nothing.
Edit : I could, as a poster suggested, modify the shortcut properties, but I'd rather use code : I don't have complete control over every computer the soft is installed on.
I don't want to remove it completely from everywhere except the systray, I just want it to start minimized.
Any ideas ?
Thanks
Select Start , select the arrow next to All apps, right-click the app, then select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.
In your main program you probably have a line of the form:
Application.Run(new Form1());
This will force the form to be shown. You will need to create the form but not pass it to Application.Run
:
Form1 form = new Form1();
Application.Run();
Note that the program will now not terminate until you call Application.ExitThread()
. It's best to do this from a handler for the FormClosed
event.
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Application.ExitThread();
}
this is how you do it
static class Program
{
[STAThread]
static void Main()
{
NotifyIcon icon = new NotifyIcon();
icon.Icon = System.Drawing.SystemIcons.Application;
icon.Click += delegate { MessageBox.Show("Bye!"); icon.Visible = false; Application.Exit(); };
icon.Visible = true;
Application.Run();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With