hi! how can I hide the form and show a Taskbar icon instead when I click the Close button in the ControlBox. Thanks in advance!
Printable View
hi! how can I hide the form and show a Taskbar icon instead when I click the Close button in the ControlBox. Thanks in advance!
I don't know the value of the Windows message received when Windows is shutting down but I do know that it has been posted in the C# and/or VB.NET forum before, and probably the VB and API forums too. I'll leave it up to you to track it down, either here or elsewhere on the Web.Code:// Indicates whether the form should be minimised rather than closed.
private bool hideOnClose = true;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.hideOnClose)
{
// Don't close the form.
e.Cancel = true;
// Minimise the form.
this.WindowState = FormWindowState.Minimized;
}
}
private void Form1_Resize(object sender, EventArgs e)
{
bool minimised = this.WindowState == FormWindowState.Minimized;
// If the form is minimised show only the tray icon, otherwise show the form but not the tray icon.
this.ShowInTaskbar = !minimised;
this.Visible = !minimised;
this.notifyIcon1.Visible = minimised;
}
protected override void WndProc(ref Message m)
{
// You need to change the 0x0 to the value for the message that is received when Windows is shutting down.
if (m.Msg == 0x0)
{
// Windows is shutting down so you must allow the form to close.
this.hideOnClose = false;
}
base.WndProc(ref m);
}
Thanks for that jmcilhinney! you really racks!!!