气球提示有问题

时间:2011-03-03 17:04:16

标签: c# mvvm notifyicon popup-balloons

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;
    }

我的问题是,如何让通知图标在显示后消失?

3 个答案:

答案 0 :(得分:2)

您是否一次关注多个气球?

来自MSDN

  

一次只能在任务栏上显示一个气球提示。当任务栏上当前显示气球提示时,尝试显示气球提示会导致超时值被忽略。

http://msdn.microsoft.com/en-us/library/ms160064.aspx

答案 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;
}