can anyone please suggest a good code example of vb.net/c# code to put the application in system tray when minized.
Add a NotifyIcon control to your form, then use the following code:
private void frm_main_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.Hide();
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
}
You may not need to set the ShowInTaskbar property.
You can leverage a built in control called NotifyIcon. This creates a tray icon when shown. @Phillip has a code example that is somewhat complete.
There is a gotcha though:
You must override your applications main form Dispose method to call Dispose on NotifyIcon, otherwise it will stay in your tray after application exits.
public void Form_Dispose(object sender, EventArgs e)
{
if (this.Disposing)
notifyIcon1.Dispose();
}
Something like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With