I have a simple WinForms program with a toolstrip menu with several buttons (e.g. closing, new profile, etc...), but I want it to minimize on a click of the "move to tray" menu item. I'm using C# on VS 2019 with .NET 3.1, this is my code so far for moving it to the system tray and bringing it back up again from the tray on a double click:
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon.Visible = true;
}
}
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
this.WindowState = FormWindowState.Normal;
notifyIcon.Visible = false;
}
Note that the application only moves to the system tray when the user is manually clicking on the minus-sign or respectively when the resize-event is triggered, but I want it to close on the click on a menu item of a toolstrip menu.