private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.Hide();
notifyIcon1.Visible = true;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
Same as the other posters solution but with a couple of modifications.
First you need this.Hide() (or this.visible = false;) to hide the form from the Alt + Tab menu.
Second make sure you call Application.Exit() instead of this.Close() from your context menus exit menu item.
Third the if statement says to only do this if the user closed the app by click the red X or pressing Alt + F4 for all other close reasons i.e. windows is shutting down, closed through the task manager, etc. the application will exit normally.