国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

WinForm實現最小化到系統托盤方法實例詳解

2020-01-24 01:49:04
字體:
來源:轉載
供稿:網友

本文實例講述了WinForm實現最小化到系統托盤方法。分享給大家供大家參考。具體分析如下:

有個叫NotifyIcon的控件

1、建個WinForm項目,其它操作略過。
2、拉個NotifyIcon控件,將屬性Visable設置成False,在Text屬性上隨便填些文件。
3、實現Form的SizeChanged事件,代碼如下:

if(this.WindowState == FormWindowState.Minimized) //判斷是否最小化{this.ShowInTaskbar = false; //不顯示在系統任務欄notifyIcon.Visible = true; //托盤圖標可見}

4、實現NotifyIcon控件的DoubleClick事件,代碼如下:

if(this.WindowState == FormWindowState.Minimized){this.ShowInTaskbar = true; //顯示在系統任務欄this.WindowState = FormWindowState.Normal; //還原窗體notifyIcon.Visible = false; //托盤圖標隱藏}

例題:

private ContextMenu notifyiconMnu;#region 最小化到任務欄/// <summary>/// 最小化到任務欄/// </summary>private void Initializenotifyicon(){  //定義一個MenuItem數組,并把此數組同時賦值給ContextMenu對象   MenuItem[] mnuItms = new MenuItem[3];  mnuItms[0] = new MenuItem();  mnuItms[0].Text = "顯示窗口";  mnuItms[0].Click += new System.EventHandler(this.notifyIcon1_showfrom);  mnuItms[1] = new MenuItem("-");  mnuItms[2] = new MenuItem();  mnuItms[2].Text = "退出系統";  mnuItms[2].Click += new System.EventHandler(this.ExitSelect);  mnuItms[2].DefaultItem = true;  notifyiconMnu = new ContextMenu(mnuItms);  notifyIcon1.ContextMenu = notifyiconMnu;  //為托盤程序加入設定好的ContextMenu對象 }private void notifyIcon1_DoubleClick(object sender, EventArgs e){  if (this.WindowState == FormWindowState.Minimized)  {    this.Show();    this.ShowInTaskbar = true;     this.WindowState = FormWindowState.Normal;     notifyIcon1.Visible = false;   }}public void notifyIcon1_showfrom(object sender, System.EventArgs e){  if (this.WindowState == FormWindowState.Minimized)  {    this.Show();    this.ShowInTaskbar = true;    this.WindowState = FormWindowState.Normal;    notifyIcon1.Visible = false;  }}public void ExitSelect(object sender, System.EventArgs e){  //隱藏托盤程序中的圖標   notifyIcon1.Visible = false;  //關閉系統   this.Close();  this.Dispose(true);}#endregionprivate void Form_main_SizeChanged(object sender, EventArgs e){  if (this.WindowState == FormWindowState.Minimized)  //判斷是否最小化  {    notifyIcon1.Visible = true;    this.Hide();    this.ShowInTaskbar = false;    Initializenotifyicon();  }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙阴县| 墨江| 洪泽县| 岳阳市| 丹东市| 南京市| 剑川县| 长治市| 宜春市| 沙洋县| 邛崃市| 金门县| 砀山县| 兴和县| 尖扎县| 铅山县| 佛学| 龙陵县| 偏关县| 城口县| 吴桥县| 邵东县| 聂荣县| 乌鲁木齐县| 靖安县| 烟台市| 顺平县| 象州县| 吉安县| 崇左市| 铁力市| 大城县| 津市市| 凤山市| 广州市| SHOW| 庄浪县| 耿马| 芷江| 松江区| 内丘县|