[轉載][C#] 按下視窗最小化時程式隱藏的圖示

System.Windows.Forms.NotifyIcon notifyIcon1;
public Form1()
{
     this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
     this.notifyIcon1.Icon = this.Icon; // 設定圖示
     this.notifyIcon1.Text = this.Text; // 設定顯示文字
     this.notifyIcon1.MouseDoubleClick += new    
     System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
}

private void Form1_Load(object sender, EventArgs e)
{
     this.Hide(); // Form隱藏
     this.notifyIcon1.Visible = true; // 隱藏圖示顯示    
}

private void Form1_SizeChanged(object sender, EventArgs e)
{  
      if (this.WindowState == FormWindowState.Minimized)
      {
            this.Hide();
            this.notifyIcon1.Visible = true;
      }
}

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

留言