views:

851

answers:

4

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.

A: 

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.

Aaron M
A: 

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.

rwmnau
+2  A: 

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).

Bob
The problem with this is that, while I can capture an icon_click event, and I know the balloon has closed at that point, I'm not sure when to display the next balloon. Displaying it immediately would lay over whatever the user is doing down there. I could do it on a delay after the click, and this still involves a timer, so I'd rather just use the timer in all instances.
rwmnau
Good point. Assuming the only thing the user can 'do down there' is activate a context menu, if you handle the menu Opening and Closed events and only display the next balloon if the context menu is not being activated. You may also want to make that decision based on what menu item the user selects
Bob
A: 

I think this post from Raymond Chen about balloon notifications may help you: http://blogs.msdn.com/oldnewthing/archive/2009/05/04/9585032.aspx

gnobal
I think this is exactly what's happening to me, but Raymond agrees that there's really no way to tell if the balloon is closed. It seems to me that the BalloonTipClosed event should fire if the balloon is closed in any way at all, but it doesn't fire if you close the balloon by clicking on the NotifyIcon, as I think it should.Perhaps I'll upgrade the framework version of my app and see if this changes the behavior.
rwmnau