HI,
我在我们的应用程序中创建气球提示。我的问题是所有气球提示都留在任务栏上,需要悬停在它们上面才能消失。
public static bool SetBalloonTip(string balloonTipTitle, string balloonTipText, ToolTipIcon balloonTipIcon)
{
bool result = false;
NotifyIcon notifyIcon;
try
{
notifyIcon = new NotifyIcon();
notifyIcon.Icon = SystemIcons.Information;
notifyIcon.BalloonTipTitle = balloonTipTitle;
notifyIcon.BalloonTipText = balloonTipText;
notifyIcon.BalloonTipIcon = balloonTipIcon;
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(30000);
result = true;
}
catch (Exception)
{
throw;
}
return result;
}
我的问题是,如何让通知图标在显示后消失?
答案 0 :(得分:2)
答案 1 :(得分:2)
找到解决方案:
第一
private static System.ComponentModel.IContainer components;
第二
public static bool SetBalloonTip(string balloonTipTitle, string balloonTipText, ToolTipIcon balloonTipIcon)
{
bool result = false;
NotifyIcon notifyIcon;
try
{
if (components == null)
{
components = new System.ComponentModel.Container();
}
notifyIcon = new NotifyIcon(components);
notifyIcon.Icon = SystemIcons.Information;
notifyIcon.BalloonTipTitle = balloonTipTitle;
notifyIcon.BalloonTipText = balloonTipText;
notifyIcon.BalloonTipIcon = balloonTipIcon;
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(30000);
result = true;
}
catch (Exception)
{
throw;
}
return result;
}
第三
public static void DisposeOfBallonTips(bool disposing)
{
try
{
// Clean up any components being used.
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
}
catch (Exception)
{
throw;
}
}
当我要清理所有DisposeOfBallonTips
时,请致电NotifyIcons
。
答案 2 :(得分:0)
我大多猜测但是试试这个
添加一个这样的事件处理程序,看它是否有帮助。
...
...
notifyIcon.BalloonTipClosed += new EventHandler(notifyIcon_BalloonTipClosed);
notifyIcon.ShowBalloonTip(30000);
...
}
static void notifyIcon_BalloonTipClosed(object sender, EventArgs e)
{
((NotifyIcon) sender).Visible = false;
}