How to organize the launch of the program immediately minimized to tray? Did collapse by clicking on the "Minimize" button:

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { this.Show(); this.WindowState = FormWindowState.Normal; notifyIcon1.Visible = false; } private void Form1_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Hide(); notifyIcon1.Visible = true; } } 

And how to organize, so that the application immediately appeared at the start of the tray, without displaying the form on the screen?

Reported as a duplicate by participants by Alexey Shimansky , user194374, pavel , lexxl , cheops 10 Aug '16 at 6:08 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • 2
    Never a duplicate - there it was about launching someone else's program, but here we are talking about our own. - Pavel Mayorov

2 answers 2

To do this, you mainly need to call Application.Run() without passing the form as a parameter to it.

If you want to have an icon in the tray, modify the Main method as follows (context menu is optional):

 static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form = new Form1(); using (NotifyIcon icon = new NotifyIcon()) { icon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); icon.ContextMenu = new ContextMenu( new [] { new MenuItem("Show form", (s, e) => form.Show()), new MenuItem("Hide form", (s, e) => form.Hide()), new MenuItem("Exit", (s, e) => Application.Exit()), }); icon.Visible = true; Application.Run(); icon.Visible = false; } } 

A source

    Minimize the window in the form load handler.

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