Here is a code snippet from form I initialization method that does just that. The application launches in the tray, and a window shows when the user double-clicks the notification icon. I have methods that handle resizing, etc., which guarantee that the form will be closed only through the menu item.
public MainForm() { ...code Resize += MainForm_Resize; notifyIcon.DoubleClick += NotifyIconDoubleClick; WindowState = FormWindowState.Minimized; Hide(); } private void MainForm_Resize(object sender, EventArgs e) { if (FormWindowState.Minimized == WindowState) Hide(); } private void NotifyIconDoubleClick(object sender, EventArgs e) { Show(); try { WindowState = FormWindowState.Normal; ...more code for other stuff }catch(yadda yadda) ...code } }
source share