文章出處
文章列表
前言
有些程序在關閉或最小化的時候會隱藏在系統托盤中,雙擊或右擊會重新顯示,winform實現其功能很簡單,這邊就簡單的介紹下。
實現
在winform實現托盤使用notifyIcon控件,如果加菜單的話再結合下contextMenuStrip控件,我們看下代碼:
1 this.notifyIcon1.Icon = new Icon(@"H:\學習資料\C# 窗體應用程序\自練\實現系統托盤\ico\qq彩色.ico"); 2 this.notifyIcon1.Visible = true; 3 this.notifyIcon1.Text = "在線";
只要設置這些屬性就行了,然后添加雙擊事件:
1 private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) 2 { 3 if (e.Button == MouseButtons.Left) 4 { 5 this.Show(); 6 this.Focus(); 7 } 8 }
就這么簡單,主要用Hide()和Show()方法隱藏和顯示窗體,其他的東西可以自由擴展。
實現效果:
程序下載:實現系統托盤.rar
文章列表
全站熱搜