Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,I am developing an application with system tray, my problem is, while closing my application,it should remove the tray icon from the system tray, but it is not refreshing the task bar. why?
your help would be appreciated...... the following is my code...

C#
private void frmMessenger_FormClosing(object sender, FormClosingEventArgs e)
        {
 notifyIcon1.Visible = false;
                notifyIcon1.Icon = null;
                notifyIcon1.Dispose();
}
Posted

You shouldn't need to do that. I am working on an app right now that lives in the system tray, and I have the Form.ShowInTaskBar property set to false - it never shows up there at all.

If you're saying that the icon remains IN THE SYSTEM TRAY after closing the app, you could try this code in your form:

C#
//---------------------------------------------------------------------
protected override void Dispose(bool disposing) 
{ 
    if (disposing) 
    { 
        this.notifyIcon1.Dispose();
    }
    base.Dispose(disposing);
}


What I've found is that if you drag a NotifyIcon control onto your form in the designer, the Dispose method in your designer.cs file will properly dispose it when the app closes. HOWEVER, if you add it manually to your .cs file, you have to add the line that specifically disposes your notifyIcon to the Dispose method in your designer.cs file.
 
Share this answer
 
v5
Try this[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900