We are using a NotifyIcon
to alert the user when they receive a new message that needs their attention. In the event that someone else gets to the message first, the notify icon should get hidden again, however I am having a problem with figuring out how to close the balloon from code behind.
My code looks something like this:
myNotifyIcon.ShowBalloonTip(2000, title, message, icon);
I have tried the suggestions found here, but none are suitable.
Using
myNotifyIcon.Visible = true
does not hide itUsing
myNotifyIcon.Visible = false; myNotifyIcon.Visible = true;
will hide it, but it also hides the icon in the tray and when it is shown again, it shows up a a different location.myNotifyIcon.Show(0)
is not a valid methodmyNotifyIcon.ShowBalloonTip(0)
ormyNotifyIcon.ShowBalloonTip(1)
does not appear to work as the balloon just gets shown and doesn't appear to go away on its own at all.
I read this question about using the WinAPI to find the window and send it a WM_CLOSE
message, but I'm not too sure how to do that reliably.
How can I close a NotifyIcon
from the code behind?
I've never found a non-hacky way to do that. The documentation says:
Even though this does not specifically address the question of explicitly closing the balloon, it indicates to me that callers of the ShowBalloonTip() method simply do not have complete control over the balloon, once it's been shown.
The best option I've found is one you already mentioned:
Not ideal, but it works. Another idea would be to change the message displayed in the balloon to indicate that the previous message is obsolete: