问题
I have a Tray icon in my application. I am showing the balloon tip for 20 seconds, when I am loading something in the background. But, if the background load gets completed early, say in 10 seconds, I would like to hide the balloon tip. Currently the only way to hide the balloon tip is to click the close icon in the balloon tip.
Public Tray As NotifyIcon
Tray = New NotifyIcon
Tray.BalloonTipIcon = ToolTipIcon.Info
Tray.BalloonTipText = "Loading"
Tray.BalloonTipTitle = "Please Wait"
Tray.ShowBalloonTip(20 * 1000)
Is it possible to hide the balloon tip programmatically before the specified time is reached?
回答1:
Try this:
Tray.Visible = true;
More info here.
Hope helps!
回答2:
There are certainly better ways to do this. "Please wait" kind of feedback is best done with a progress bar or an hourglass mouse cursor. You can make it fancy on Win7+ with the Windows API Code Pack by displaying progress in the task bar button.
Anyhoo, you can pop a balloon by displaying another one with a short time-out or hiding the notification icon.
回答3:
You can at any time hide the balloon tip (Visible property).
Note that tray icons and balloons are owned and controlled by explorer.exe ("start menu bar"), so if you don't clean it up properly it will stay there. You need to actively tell it to disappear. Setting a timer for the baloon simply tells explorer how long to show it. You need to actively send a counter-message to hide it before.
回答4:
I'd personally think that it would be easier to just call
Tray.Show(0);
Which should force it to immediately hide the tray baloon without hiding the tray icon itself...
回答5:
At least on current Windows 8.1 using .Net Framework 4 Client Profile,
popping BallonTip while keeping System.Windows.Forms.NotifyIcon notifyIcon1 visible
wanted back-to-back:
notifyIcon1.Visible = false;
notifyIcon1.Visible = true;
来源:https://stackoverflow.com/questions/5314699/how-to-close-balloontip-programmatically