即使关闭应用程序,NotifyIcon仍保留在托盘中,但在鼠标悬停时消失 [英] NotifyIcon remains in Tray even after application closing but disappears on Mouse Hover

查看:287
本文介绍了即使关闭应用程序,NotifyIcon仍保留在托盘中,但在鼠标悬停时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于SO的许多问题都提出了同样的疑问。
解决方案是设置

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

notifyIcon.icon = null 并调用在FormClosing事件中为其处理

在我的应用程序中,没有这样的表单,但是具有通知图标,该图标会在事件上更新。
创建时,我隐藏了表单,并设置了 ShowInTaskbar 属性 false 。因此,我不能有 FormClosing或 FormClosed事件。

In my application, there is no such form but has Notification icon which updates on Events. On creation, I hide my form and make ShowInTaskbar property false. Hence I can not have a "FormClosing" or "FormClosed" events.

如果此应用程序退出事件,它将调用 Process.GetCurrentProcess( ).Kill(); 退出。

If this application gets event to exit, It calls Process.GetCurrentProcess().Kill(); to exit.

我添加了 notifyIcon.icon = null 以及在杀死之前进行处理,但是在我将鼠标悬停在其上之前,图标仍然会保留在任务栏上。

I have added notifyIcon.icon = null as well as Dispose before killing, but still icon remains taskbar until I hover mouse over it.

编辑:如果我认为行为是由于调用 GetCurrentProcess()。Kill()而引起的,是否有任何优雅的方法可以退出应用程序,从而清除所有资源并从系统任务栏中删除图标。

EDIT: If I assume that this behaviour is due to calling GetCurrentProcess().Kill(), Is there any elegant way to exit from application which will clear all resources and remove icon from system tray.

推荐答案

您可以设置

notifyIcon1.Visible = false;

OR

notifyIcon.Icon = null;

在表单关闭事件中。

这篇关于即使关闭应用程序,NotifyIcon仍保留在托盘中,但在鼠标悬停时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆