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

后端 未结 14 1307
清歌不尽
清歌不尽 2020-12-03 00:08

There are many questions on SO asking same doubt. Solution for this is to set

notifyIcon.icon = null and calling Dispose for it in FormClo

14条回答
  •  伪装坚强ぢ
    2020-12-03 01:04

    Use this code when you want to do it when you press the Exit or Close button:

    private void ExitButton_Click(object sender, EventArgs e)
    {
        notifyIcon.Dispose();
        Application.Exit(); // or this.Close();
    }
    

    Use this code when you want to do it when the form is closing:

    private void Form1_FormClosing(object sender, EventArgs e)
    {
        notifyIcon.Dispose();
        Application.Exit(); // or this.Close();
    }
    

    The important code is this:

    notifyIcon.Dispose();
    

提交回复
热议问题