Perhaps my question is duplicating this. Several icons open in the tray panel . In my winforms application, I show the application in the system tray after closing the form, i.e. The application does not exit after closing the form, but exits when you click "Close" in the "Right Click" context menu on the Applicaion taskbar.
But when I continue to use the application, I notice that there are many notification icons in the system tray. But as soon as the mouse runs over them, they all disappear, except for those that have the application running. I tried each method to eliminate the multiple icon, but I can not do this.
Below is my code To minimize the system tray
public void MinimizeToTray() { try { this.WindowState = FormWindowState.Minimized; TrayIcon.Visible = true; TrayIcon.ShowBalloonTip(1000); ShowInTaskbar = false;
On loading the form, I added this code
private void LoadTrayMenu() { TrayMenu.Items.Add("Reminder"); TrayMenu.Items.Add("Close"); TrayMenu.Items[0].Click += new EventHandler(this.Reminder_Click); TrayMenu.Items[1].Click += new System.EventHandler(this.Dispose_Click); TrayIcon.ContextMenuStrip = TrayMenu; }
The dispose event is as follows
private void Dispose_Click(object Sender, EventArgs e) { TrayIcon.Visible = false; TrayIcon.Icon = null; TrayIcon.Dispose(); this.Dispose(); }
When I clicked the icon, I wrote the following code
private void TrayIcon_MouseClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { this.Show(); this.WindowState = FormWindowState.Normal; TrayIcon.Visible = false;
I tried to clear the notification icons, but even that didn't help me. I missed something really obvious. Any help would be appreciated.