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

后端 未结 14 1207
清歌不尽
清歌不尽 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:09

    i can tell you can solve the problem simply using the .dispose() method, but that is not called if you kill the process instead of exit the application.

    please refer to Application.Exit if you have built a simple Windows Form application else refer to Environment.Exit that is more general.

    0 讨论(0)
  • 2020-12-03 01:10

    The right answer has already been given. But you must also provide a delay, for example with a timer. Only then the application can still remove the icon in the background.

    private System.Windows.Forms.Timer mCloseAppTimer;
    private void ExitButton_Click(object sender, EventArgs e) 
    { 
        notifyIcon.Visible = false; notifyIcon.Dispose; 
        mCloseAppTimer = new System.Windows.Forms.Timer(); 
        mCloseAppTimer.Interval = 100; 
        mCloseAppTimer.Tick += new EventHandler(OnCloseAppTimerTick); 
    } 
    private void OnCloseAppTimerTick(object sender, EventArgs e) 
    { 
        Environment.Exit(0); // other exit codes are also possible 
    }
    
    0 讨论(0)
提交回复
热议问题