2011-03-03 104 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

我認爲只有當用戶主動關閉氣球時才引發該事件。 –