Search code examples
c#mvvmnotifyiconpopup-balloons

Problem with balloon tips


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;

            notifyIcon.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?


Solution

  • 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.