C#实现窗口最小化到系统托盘
生活随笔
收集整理的這篇文章主要介紹了
C#实现窗口最小化到系统托盘
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關鍵字:C# 最小化 托盤
原文:http://www.cnblogs.com/txw1958/archive/2012/12/17/csharp-minimize-tray.html
先添加notifyicon控件notifyIcon1
?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace notifyIconShow {public partial class ColdJoke : Form{#region//創建NotifyIcon對象 NotifyIcon notifyicon = new NotifyIcon();//創建托盤圖標對象 Icon ico = new Icon("snow.ico");//創建托盤菜單對象 ContextMenu notifyContextMenu = new ContextMenu();#endregionpublic ColdJoke(){InitializeComponent();}#region 托盤提示private void Form1_Load(object sender, EventArgs e){//設置鼠標放在托盤圖標上面的文字 this.notifyIcon1.Text = "笑話";}#endregion#region 隱藏任務欄圖標、顯示托盤圖標private void Form1_SizeChanged(object sender, EventArgs e){//判斷是否選擇的是最小化按鈕 if (WindowState == FormWindowState.Minimized){//托盤顯示圖標等于托盤圖標對象 //注意notifyIcon1是控件的名字而不是對象的名字 notifyIcon1.Icon = ico;//隱藏任務欄區圖標 this.ShowInTaskbar = false;//圖標顯示在托盤區 notifyicon.Visible = true;}}#endregion#region 還原窗體private void notifyIcon1_DoubleClick(object sender, EventArgs e){//判斷是否已經最小化于托盤 if (WindowState == FormWindowState.Minimized){//還原窗體顯示 WindowState = FormWindowState.Normal;//激活窗體并給予它焦點 this.Activate();//任務欄區顯示圖標 this.ShowInTaskbar = true;//托盤區圖標隱藏 notifyicon.Visible = false;}}#endregion}}?
轉載于:https://www.cnblogs.com/txw1958/archive/2012/12/17/csharp-minimize-tray.html
總結
以上是生活随笔為你收集整理的C#实现窗口最小化到系统托盘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [每天进步一点 -- 流水账]第1周
- 下一篇: 算法——海量数据(5%)