开发者

Problem with balloon tips

开发者 https://www.devze.com 2023-02-15 03:08 出处:网络
HI, I create balloon tips all over our application. My problem is that all of the balloon tips stay on the task-bar and needs to be hovered over for them to disappear.

HI,

I create balloon tips all over our application. My problem is that all of the balloon tips stay on the task-bar and needs to be hovered over for them to disappear.

        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;

            notify开发者_开发技巧Icon.Visible = true;
            notifyIcon.ShowBalloonTip(30000);

            result = true;
        }
        catch (Exception)
        {

            throw;
        }

        return result;
    }

My question is, how do i make the notify icon disappear after it has been shown?


Found a solution:

first:

private static System.ComponentModel.IContainer components;

Second:

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

Third:

        public static void DisposeOfBallonTips(bool disposing)
    {
        try
        {
            // Clean up any components being used.
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

Calling DisposeOfBallonTips when i want to clean up all NotifyIcons.


Are you displying more than one balloon at a time?

From MSDN:

Only one balloon tip can display on the taskbar at a time. Attempting to display a balloon tip when one is currently displayed on the taskbar causes the timeout value to be ignored.

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


I'm mostly guessing but try this

add an event handler like this and see if it helps.

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



static void notifyIcon_BalloonTipClosed(object sender, EventArgs e)
{
    ((NotifyIcon) sender).Visible = false;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号