0

I have this code :

private void Form1_Resize(object sender, EventArgs e)
        {
            if (FormWindowState.Minimized == WindowState)
                Hide();
        }

        private void CloseApplication_Click(object sender, EventArgs e)
        {
            this.Close();
        }

Then i resize hide the form or not resizing it i'm going with the mouse to the tray icon right click then select close application the Form is closed the application is closed.

But sometimes the icon of the application is stay in the tray icon and only if i move my mouse cursour over the icon he is gone . How can i make sure that when i close my application the icon in the tray icon will move/gone away ?

Revuen Ben Dror
  • 237
  • 7
  • 17
  • 1
    I have seen this happen with many different applications in the system tray. I don't think it's a bug with your code-I think it's a bug in Explorer.exe. See http://forums.devx.com/showthread.php?37092-How-to-refresh-system-tray – mason Jun 04 '13 at 20:01
  • Try setting `this.ShowInTaskbar` to `false`, before calling `Close()`. – Mohammed Hossain Jun 04 '13 at 20:02
  • I have also seen this happening with my many applications even some of those of Microsoft. – Guanxi Jun 04 '13 at 20:06
  • 1
    You are forgetting to call the NotifyIcon.Dispose() method. Best avoided by dropping it on the form so it is automatic. – Hans Passant Jun 04 '13 at 20:22

2 Answers2

1

You can either set

notifyIcon1.Visible = false;

or

notifyIcon.Icon = null;

in the form closing event.

(from NotifyIcon remains in Tray even after application closing but disappears on Mouse Hover )

Community
  • 1
  • 1
Kendall Trego
  • 1,975
  • 13
  • 21
0

I've had the same problem. For me, setting

notifyIcon.Visible = false;

works fine and notify icon immediately dissapears from system tray.

FrenkyB
  • 6,625
  • 14
  • 67
  • 114