如何判断系统托盘中的气球提示是否已关闭?

发布于 2024-07-22 04:56:38 字数 475 浏览 9 评论 0原文

我有一个应用程序,它使用托盘中的 NotifyIcon 来隐藏/恢复应用程序,并向用户弹出应用程序事件通知。 我的应用程序有一个通知队列,我使用NotificationIcon.BalloonTipClosed 事件来确定何时重置气球并显示下一个通知(如果队列中有一个)。

此方法似乎在两种常见原因中都很有效(用户让气球在超时时自行关闭,并且用户单击气球中的“X”以强制其关闭),但还有第三种情况,即 BalloonTipClosed 不会被调用:

  1. 通知气球弹出
  2. 虽然它是可见的,但用户右键单击通知图标以调出上下文菜单,导致气球消失

在这种情况下,BalloonTipClosed 事件不会被触发 - 我认为这是框架中的一个错误(我是使用 2.0),但是有人对此有什么想法吗? 如果我没有收到此事件,我的应用程序总是认为有一个可见的气球(我有一个布尔值可以防止它同时显示多个气球),并且只要它正在运行,它就永远不会再显示另一个图标。

I have an application that uses a NotifyIcon in the tray to hide/restore the application, as well as pop up notices to the user of application events. My application has a notification queue, and I use the NotificationIcon.BalloonTipClosed event to determine when to reset the balloon and show the next notification (if there's one in the queue).

This method seems to work great in both usual causes (user lets the balloon close itself when it times out, and user clicks "X" in balloon to force it to close), but there's a third case where BalloonTipClosed doesn't get called:

  1. Notification balloon pops up
  2. While it's visible, user right-clicks on notification icon to bring up context menu, causing the balloon to disappear

The BalloonTipClosed event doesn't get triggered in this instance - I figure it's a bug in the framework (I'm using 2.0), but does anybody have an idea around this? If I don't get this event, my application always thinks there's a balloon visible (I have a boolean that prevents it from displaying multiple balloons at once), and it will never show another icon again, as long as it's running.

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

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

发布评论

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

评论(4

音盲 2024-07-29 04:56:38

这属于对 Aarons 答案的评论,但我还不能发表评论。

如果您处理 NotifyIcon(以及 BalloonTipClosed)上的 BalloonTipClicked 和 MouseClick 事件,那么您可以捕获气球关闭的所有方式。 您唯一需要注意的是,多个场景将触发多个事件,因此请务必围绕该事件进行编码(例如 isClosed = true,然后在显示新气球时重置它)。

This belongs as a comment to Aarons answer, but I am not allowed to comment yet.

If you handle the BalloonTipClicked and MouseClick events on the NotifyIcon (as well as the BalloonTipClosed) then you can capture all the ways the balloon can close. The only thing you have to be aware of is that several scenerios will trigger multiple events, so be sure to code around that (something like isClosed = true, and then reset that when a new balloon is displayed).

我一向站在原地 2024-07-29 04:56:38

在 BalloonTipClicked 事件的事件处理程序中,我将检查是否单击了鼠标右键,以及是否将布尔值设置为 false。

In the event handler for the BalloonTipClicked Event, I would check to see if the right mouse button was clicked, and if it was set the boolean to false.

却一份温柔 2024-07-29 04:56:38

这就是我最终所做的,尽管我不是特别喜欢这个解决方案。 我在表单中添加了第二个计时器并将其设置为 10 秒。 当弹出通知时(当我弹出通知时),我启动计时器,然后在 BalloonTipClosed 中停止它。 如果计时器滴答作响(意味着 BalloonTipClosed 尚未运行),我会手动显示下一个提示。

结果是,如果它还没有被触发,我就会处理它。 不过,如果有人有更好的解决方案,我愿意接受。

Here's what I ended up doing, though I don't particularly like this solution. I added a second timer to the form and set it for 10 seconds. When a notification pops up (when I pop one), I start the timer, and then in BalloonTipClosed, I stop it. If the timer ticks (meaning that BalloonTipClosed hasn't run yet), I display the next tip manually.

The result is that if it hasn't fired yet, I take care of it. However, I'm open to better solutions if anybody has one.

可爱咩 2024-07-29 04:56:38

我认为 Raymond Chen 这篇关于气球通知的文章可能对您有帮助:
https://devblogs.microsoft.com/oldnewthing/20090504-00/? p=18363

I think this post from Raymond Chen about balloon notifications may help you:
https://devblogs.microsoft.com/oldnewthing/20090504-00/?p=18363

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