2011-03-03 62 views
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; 
    } 

我的问题是,如何使该通知已被证明后,图标会消失?

回答

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

当我想清理所有NotifyIcons时,致电DisposeOfBallonTips

+0

寻找此@Willem。谢谢 – Rezoan

0

我主要猜测,但尝试这个

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

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



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

我认为只有当用户主动关闭气球时才引发该事件。 –