jmcilhinney
Oct 30th, 2008, 08:19 PM
VB version here (http://www.vbforums.com/showthread.php?t=454466).
In previous versions minimising to the system tray instead of closing a form was a hassle. You had to mess about checking whether the system was shutting down, etc. or else your app would prevent Windows from ever closing. In .NET 2.0 that process is simplified consideralbly:private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
// The user has requested the form be closed so mimimise to the system tray instead.
e.Cancel = true;
this.Visible = false;
this.notifyIcon1.Visible = true;
}
}This will minimise the form to the system tray if the user requests the close by clicking the Close button on the title bar, selecting Close from the system menu, pressing Alt+F4 or performing some action that causes your code to call the form's Close method. All other reasons for closure, including calling Application.Exit or Windows shutting down, will cause the form to actually close.
In previous versions minimising to the system tray instead of closing a form was a hassle. You had to mess about checking whether the system was shutting down, etc. or else your app would prevent Windows from ever closing. In .NET 2.0 that process is simplified consideralbly:private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
// The user has requested the form be closed so mimimise to the system tray instead.
e.Cancel = true;
this.Visible = false;
this.notifyIcon1.Visible = true;
}
}This will minimise the form to the system tray if the user requests the close by clicking the Close button on the title bar, selecting Close from the system menu, pressing Alt+F4 or performing some action that causes your code to call the form's Close method. All other reasons for closure, including calling Application.Exit or Windows shutting down, will cause the form to actually close.