2012-10-19 9 views
1

아이콘이 여전히 트레이에 남아 있습니다. 마우스 커서를 가져 가면 사라집니다.풍선 도움말이 닫힌 후 C# NotifyIcon이 트레이에 남아 있습니다. 내 NotifyIcon의 Ballon Tip이 닫힌 후에도

하나의 구성 요소 인 NotifyIcon이있는 Notification.cs 클래스가 있습니다.

특정 조건이 충족 될 때만 알림을 표시하기 때문에 콘솔 응용 프로그램에서 호출합니다.

일부 코드 :

내 프로그램 내에서 알림 호출 방법
  • :

    Notification not = new Notification("Error occured, do this or that", "Some error", System.Windows.Forms.ToolTipIcon.Error); 
    not.getIcon().ShowBalloonTip(1000); 
    
  • 알림 클래스 :

    public Notification(string baloonTipText, string baloonTipTitle, System.Windows.Forms.ToolTipIcon icon) : this() 
    { 
        this.icon.Visible = true; 
        this.icon.BalloonTipText = baloonTipText; 
        this.icon.BalloonTipTitle = baloonTipTitle; 
        this.icon.BalloonTipIcon = icon; 
    } 
    
    public System.Windows.Forms.NotifyIcon getIcon() 
    { 
        return this.icon; 
    } 
    
    private void icon_BalloonTipClosed(object sender, EventArgs e) 
    { 
        this.icon.Visible = false; 
        this.icon.Dispose();    
    } 
    

어떤 아이디어?

+0

[같은 질문] (http://stackoverflow.com/questions/10980029/notify-icon-stays-in-system-tray-on-application-close)를 얼마 전에 대답이 없지만 몇 가지 유용한 의견이 있습니다. – JMK

+0

@JMK 저는 이것이 같은 질문이라는 것을 확신하지 못합니다. 이 질문을 읽는 방식으로, 프로그램은 여전히 ​​실행 중입니다. – hvd

+0

어떤 종류의'type'이'Notification' 클래스입니까? –

답변

2

콘솔 응용 프로그램에서 실행 중이므로 풍선 도움말이 닫힐 때 (메시지 펌프 없음) icon_BalloonTipClosed 핸들러가 호출되지 않습니다. 풍선 도움말의 시간 초과보다 긴 시간 제한을 사용하여 응용 프로그램이 종료되거나 타이머 (System.Threading.Timer, System.Windows.Forms.Timer가 작동하지 않음)를 설정하면 수동으로 Dispose으로 전화해야합니다. 예 :

timer = new Timer(state => not.getIcon().Dispose(), null, 1200, Timeout.Infinite); 
+0

주말 이후에 시도해보고 작동하는지 알려줍니다. 감사! – wojtuch

0
using System; 
using System.ComponentModel; 
using System.Drawing; 
using System.IO; 
using System.Reflection; 
using System.Windows.Forms; 

namespace ShowToolTip 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void btBallonToolTip_Click(object sender, EventArgs e) 
     { 
      ShowBalloonTip(); 
      this.Hide(); 
     } 

     private void ShowBalloonTip() 
     { 
      Container bpcomponents = new Container(); 
      ContextMenu contextMenu1 = new ContextMenu(); 

      MenuItem runMenu = new MenuItem(); 
      runMenu.Index = 1; 
      runMenu.Text = "Run..."; 
      runMenu.Click += new EventHandler(runMenu_Click); 

      MenuItem breakMenu = new MenuItem(); 
      breakMenu.Index = 2; 
      breakMenu.Text = "-------------"; 

      MenuItem exitMenu = new MenuItem(); 
      exitMenu.Index = 3; 
      exitMenu.Text = "E&xit"; 

      exitMenu.Click += new EventHandler(exitMenu_Click); 

      // Initialize contextMenu1 
      contextMenu1.MenuItems.AddRange(
         new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu }); 

      // Initialize menuItem1 

      this.ClientSize = new System.Drawing.Size(0, 0); 
      this.Text = "Ballon Tootip Example"; 

      // Create the NotifyIcon. 
      NotifyIcon notifyIcon = new NotifyIcon(bpcomponents); 

      // The Icon property sets the icon that will appear 
      // in the systray for this application. 
      string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\setup-icon.ico"; 
      notifyIcon.Icon = new Icon(iconPath); 

      // The ContextMenu property sets the menu that will 
      // appear when the systray icon is right clicked. 
      notifyIcon.ContextMenu = contextMenu1; 

      notifyIcon.Visible = true; 

      // The Text property sets the text that will be displayed, 
      // in a tooltip, when the mouse hovers over the systray icon. 
      notifyIcon.Text = "Morgan Tech Space BallonTip Running..."; 
      notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running..."; 
      notifyIcon.BalloonTipTitle = "Morgan Tech Space"; 
      notifyIcon.ShowBalloonTip(1000); 
     } 

     void exitMenu_Click(object sender, EventArgs e) 
     { 
      this.Close(); 
     } 

     void runMenu_Click(object sender, EventArgs e) 
     { 
      MessageBox.Show("BallonTip is Running...."); 
     } 
    } 
} 
내가 물었다
관련 문제