All you have to do is call Hide()
and Show()
when you want to hide and show your form.
NOTE: Hide()
will hide from taskbar as well.
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
You may hide and show the NotifyIcon
opposite to the form to not have a icon when the form is shown.
Obviously you need a NotifyIcon
to display your app in the system tray.
Finally your code will look like this:
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}