Notify applications where the form disappears from the taskbar on minimize

Jim asks:

"I've been following your Windows Forms articles, and was hoping that you could post about the correct way to minimize a Windows Form to the tray. The ShowInTask property of the Form is mentioned in newsgroups, but the Form still shows in the Alt+Tab list."

The best way to handle this situation is to actually close the form. Then the form cannot possibly be in the ALT+Tab list. This article discusses how to build notify applications which close the form on minimize

private void CalendarForm_SizeChanged(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Minimized) {
this.Close();
}
}

Note that this would usually end your application - you'll either need to use Application.Run() instead or a custom ApplicationContext. This is discussed in the above article.

"Also, I've noticed that applications such as Messenger animate the window correctly towards the tray, which is different from the WindowState/ShowInTaskBar behavior."

Here my recommendation would be to cancel the closing event on the form and use a System.Windows.Forms.Timer to shrink the form to the bottom right of the working area. The rough idea would be

     System.Windows.Forms.Timer timer = new Timer(components);

   private bool animationComplete = false;

   private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
// in 2.0 could also check if e.CloseReason == CloseReason.UserClosing
// in 1.1 can use the Form.Closing event instead.
            if (!animationComplete) {
e.Cancel = true;
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 10;
timer.Enabled = true;
}
}
           

   // you may have to play with this code to get the desired effect you want
     void timer_Tick(object sender, EventArgs e) {
Rectangle workingArea = Screen.GetWorkingArea(this.Bounds);

            this.Bounds = new Rectangle(
Math.Max(workingArea.Width - this.Width, this.Left + 10),
Math.Max(workingArea.Height - this.Height, this.Top + 10),
Math.Max(0, this.Width - 10),
Math.Max(0, this.Height-10));

            if (this.Bounds.Bottom >= workingArea.Bottom) {
timer.Tick -= new EventHandler(timer_Tick);
timer.Enabled = false;
                animationComplete = true;
this.Close();
}

}
}

Hope this helps! 

Related Article: https://www.windowsforms.net/articles/notifyiconapplications.aspx