Handle the form’s Resize event. In this handler, you override the
basic functionality of the Resize event to make the form minimize to
the system tray and not to the taskbar. This can be done by doing the
following in your form’s Resize event handler:
- Check whether the form’s WindowState property is set to FormWindowState.Minimized. If yes, hide your form, enable the NotifyIcon object, and show the balloon tip that shows some information.
- Once the WindowState becomes FormWindowState.Normal, disable the NotifyIcon object by setting its Visible property to false.
- Now, you want the window to reappear when you double click on the NotifyIcon object in the taskbar. For this, handle the NotifyIcon’s
MouseDoubleClick
event. Here, you show the form using the Show()
method.
In the form resize event, do the check there and hide the form
private void Form_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
}
}
Then when clicking on the taskbar icon just restore it.
private void notifyIcon_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
Refer:
How do I minimize a WinForms application to the notification area?
minimize app to system tray