首頁 类库下载 C#類別庫 C# 托盤程式 實例 雙擊顯示窗體,最小化到托盤

C# 托盤程式 實例 雙擊顯示窗體,最小化到托盤

Nov 10, 2016 am 09:15 AM

點選工作列  顯示-隱藏切換,右鍵選單,捕捉關閉窗體事件

public partial class frmMain : Form  
   {  
       public frmMain()  
       {  
           InitializeComponent();  
       }  
  
  
       #region 注销  
   
   
       public void Logout()  
       {  
           if (MessageBox.Show("确认要退出吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)  
           {  
               notifyIcon1.Visible = false;  
               FormCollection fc = Application.OpenForms;  
               if (fc != null && fc.Count > 0)  
               {  
                   foreach (Form window in fc)  
                   {  
                       window.Hide();  
                   }  
               }  
               CacheHelper.CurrentUsrName = "";  
               CacheHelper.CurrentRoleId = 0;  
               frmLogin fl = new frmLogin();  
               fl.Show();  
           }  
   
   
       }  
   
   
       private void 注销登陆ToolStripMenuItem_Click(object sender, EventArgs e)  
       {  
           Logout();  
       }  
  
  
       #endregion  
  
  
       #region 修改密码  
   
   
       private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)  
       {  
           frmChangePwd fcp = new frmChangePwd();  
           fcp.Show();  
       }  
  
  
       #endregion  
   
   
       private void frmMain_Load(object sender, EventArgs e)  
       {  
   
   
       }  
   
   
       private void frmMain_FormClosing(object sender, FormClosingEventArgs e)  
       {  
           if (MessageBox.Show("确认要退出吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)  
           {  
               Logout();  
           }  
           else 
           {  
               e.Cancel = true;  
           }  
       }  
   
   
       private void 最大化ToolStripMenuItem_Click(object sender, EventArgs e)  
       {  
           ShowWin();  
       }  
   
   
       private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)  
       {  
           Logout();  
       }  
   
   
       private void frmMain_SizeChanged(object sender, EventArgs e)  
       {  
           if (this.WindowState == FormWindowState.Minimized)  
           {  
               HideWin();  
           }  
       }  
   
   
       private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)  
       {  
           if (e.Button == MouseButtons.Right)  
           {  
               contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);  
           }  
           else 
           {  
               ShowWin();  
           }  
       }  
  
  
       #region 隐藏显示窗体  
   
   
       /// <summary>  
       /// 隐藏窗体  
       /// </summary>  
       private void HideWin()  
       {  
           this.notifyIcon1.Visible = true;  
           this.Hide();  
       }  
   
   
       /// <summary>  
       /// 显示主窗体  
       /// </summary>  
       private void ShowWin()  
       {  
           if (Visible)  
           {  
               HideWin();  
           }  
           else 
           {  
               /////这里注意顺序很重要,先show 后设置state  
               Show();  
               WindowState = FormWindowState.Normal;  
           }  
       }  
  
  
       #endregion  
   }
登入後複製


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)