你好,
我在整个应用程序中创建气球提示。我的问题是所有气球提示都留在任务栏上,需要悬停它们才能消失。
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;
}
我的问题是,如何让通知图标在显示后消失?
请您参考如下方法:
找到解决方案:
首先:
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;
}
}
当我想清理所有 NotifyIcons 时调用 DisposeOfBallonTips。
