2011-04-12 149 views
2

我將notifyIcon添加到容器並設置Visible = true選項,但沒有出現圖標。如何在沒有Form的情況下創建notifyIcon?

private void InitializeComponent() 
     { 
      this.components = new System.ComponentModel.Container(); 
      this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); 
      this.SuspendLayout(); 
      // 
      // notifyIcon1 
      // 
      this.notifyIcon1.Text = "Manager"; 
      this.notifyIcon1.Visible = true; 
      // 
      // Form1 
      // 
      this.ClientSize = new System.Drawing.Size(0, 0); 
      this.ShowInTaskbar = false; 
      this.Visible = false; 

     } 

回答

2

我相信你需要添加一些事件,這個工作,希望這有助於

public Form2() 
    { 
     InitializeComponent(); 
     notifyIcon1.Icon = SystemIcons.Asterisk; 
     notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);// to bring it back 
     this.Resize += new EventHandler(Form2_Resize);// to move it to tray 
    } 

    void notifyIcon1_DoubleClick(object sender, EventArgs e) 
    { 
     Show(); 
     this.BringToFront(); 
     this.WindowState = FormWindowState.Normal; 
    } 

    void Form2_Resize(object sender, EventArgs e) 
    { 
     if (this.WindowState ==FormWindowState.Minimized) 
      Hide(); 
    } 
+1

謝謝。只需要notifyIcon1.Icon = SystemIcons.Asterisk; – BILL 2011-04-12 11:32:47

0

notify當窗體最小化時顯示圖標。試試這個

this.WindowState = FormWindowState.Minimized; 
+0

無影響。圖標未出現。 – BILL 2011-04-12 11:26:41

相關問題