如何保证NotifyIcon消失?

发布于 2024-07-14 18:28:57 字数 379 浏览 4 评论 0原文

我在我的一个子(模式)表单中使用 NotifyIcon 控件,它工作正常。 按预期显示气球提示,处理鼠标事件等...但是它并没有在我期望的时候消失。 具体来说,当我退出子窗体并且父窗体重新获得控制时,图标仍然保留。 它的工具提示是可访问的,因此它非常“活跃”。

当我整个退出应用程序时,图像仍然保留,直到我将光标悬停在其上。 一旦鼠标移动它就会消失。

我怎样才能让它正常工作? 好的通常是一个坏词:-0 当创建它的表单消失时,如何让它消失?

有人可以解释一下是什么原因造成的吗?我认为 .net 应该自行清理?

G

编辑:如果我在关闭的表单中调用 Dispose 方法,这可以工作,但我真的必须这样做吗? G

I'm using a NotifyIcon control in one of my child (modal) forms and it is working fine. SHowing balloon tips as expected, handling mouse events etc... It doesn't however vanish when I would expect it to. Specifically, when i exit the child form and the parent is back in control the icon still remains. It's tooltip is accessible so it is very much "alive" as it were.

When I then exit my application as a whole the image still remains until the point i hover the cursor over it. Once moused it disappears.

How can I get it to behave normally? Ok normally is a bad word :-0 How can I get it to disappear when the form that created it disappears?

Could someone explain what is causing this as well, I thought .net was supposed to clean up after itself?

G

EDIT: If I call the Dispose method in the form closed evernt this works, but do I really have to do this? G

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转身泪倾城 2024-07-21 18:28:57

这是一个想法,不确定这是否会产生影响,但是当子窗体关闭时,您是否在 NotifyIcon 上调用 Dispose() ?

编辑:刚刚看到您的编辑,是的,我对这有帮助并不感到惊讶,是的,您应该这样做。 在幕后,某些东西正在使用一些非托管资源,您需要释放它。 一般来说,应用程序中实现您正在使用的 IDisposable 的任何内容,请帮自己一个忙并处理它。

Here's a thought, not sure if this will make a difference, but are you calling Dispose() on the NotifyIcon when the child form closes?

EDIT: Just saw your edit, yes I'm not surprised that this helps, and yes you should do it. Under the covers something is using some unmanaged resourced, and you need to release it. Generally, anything in your app that implements IDisposable that you're using, do yourself a favor and Dispose it.

可可 2024-07-21 18:28:57
Icon.Visible = false

也会起作用。 不管怎样,仍然应该调用Dispose来处置Windows句柄。

Icon.Visible = false

would also work. Anyway, Dispose should still be called to dispose of the Windows handle.

︶葆Ⅱㄣ 2024-07-21 18:28:57

这个问题 类似。

如果您同意新程序实例清理系统托盘,而不是尝试保证在任何类型的关闭时进行清理,则 以下 模拟通知托盘清理。 它使用 SendMessage 解决方案来模拟用户鼠标悬停清理,而无需实际移动用户的光标。

请注意,在 Windows 7 计算机上,名称通知区域 应替换为用户升级通知区域

This question is similar.

If you're okay with new program instances cleaning up the system-tray instead of trying to guarantee cleanup on any kind of shut down, the following simulates a notification tray cleanup. It uses a SendMessage solution that simulates a user-mouse-over cleanup that doesn't involve needing to actually move the user's cursor around.

Note that on Windows 7 machines the name Notification Area should be replaced with User Promoted Notification Area.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文