C# 窗体最小化的托盘/系统通知区域(转)
1.在form中添加一個NotifyIcon控件
2.把1.ico這個圖標放在binDebug目錄下
先看看效果圖:
?
?
3.代碼的實現
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
??? public partial class Form1 : Form
??? {
??????? public Form1()
??????? {
??????????? InitializeComponent();
??????????? this.Text = "實現最小托盤";
??????????? this.notifyIcon1.Icon = new Icon("1.ico");//設置當前圖標
??????? }
??????? private void button1_Click(object sender, EventArgs e)
??????? {
??????????? WindowState = FormWindowState.Minimized;//最小化時隱藏窗體
??????????? //this.Visible = false; //是否顯示該控件
??????????? this.notifyIcon1.Visible = true;???? //圖標在任務欄區域中可見
??????????? this.notifyIcon1.ShowBalloonTip(300, "哈哈", "窗體成功隱藏了", ToolTipIcon.Info); //設置氣球狀工具提示顯示的時間為10秒
??????????? this.ShowInTaskbar =false;//windows任務欄中不顯示窗體
??????? }
??????? private void button2_Click(object sender, EventArgs e)
??????? {
??????????? WindowState = FormWindowState.Maximized; //窗體最大化
??????? }
??????? private void button3_Click(object sender, EventArgs e)
??????? {
??????????? WindowState = FormWindowState.Normal; //窗體常規
??????? }
??????? private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
??????? {
??????????? if (this.WindowState == FormWindowState.Minimized)//判斷是否窗體最小化
??????????? {
??????????????? this.WindowState = FormWindowState.Normal;
??????????? }
??????????? this.Activate();//激活窗體
??????????? this.notifyIcon1.Visible = false;//在任務欄區域中不顯示圖標
??????????? this.ShowInTaskbar = true; //窗體在任務欄區域中可見
??????? }
??? }
}
轉載于:https://www.cnblogs.com/haik/archive/2010/03/29/1700021.html
總結
以上是生活随笔為你收集整理的C# 窗体最小化的托盘/系统通知区域(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从godaddy转出域名
- 下一篇: Linux路由器的架设