1

你好,

我在我们的应用程序中创建了气球提示。我的问题是所有气球提示都留在任务栏上,需要悬停在上面才能消失。

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

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

4

3 回答 3

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

于 2011-03-04T10:04:44.343 回答
2

您是否一次显示多个气球?

来自MSDN

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

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

于 2011-03-03T17:18:12.800 回答
0

我主要是在猜测,但试试这个

添加这样的事件处理程序,看看它是否有帮助。

     ...
     ... 
     notifyIcon.BalloonTipClosed += new EventHandler(notifyIcon_BalloonTipClosed);
     notifyIcon.ShowBalloonTip(30000);
     ...
}



static void notifyIcon_BalloonTipClosed(object sender, EventArgs e)
{
    ((NotifyIcon) sender).Visible = false;
}
于 2011-03-03T17:32:46.973 回答