在上一篇《C# WinForm窗口最小化到系統托盤》基礎上,添加一個Timer 控件Splashtimer
觸發事件:
private void Splashtimer_Tick(object sender, System.EventArgs e)
{
if ( m_bFlag == true )
{
this.notifyIcon1.Icon = m_Icon2;
m_bFlag = false;
}
else
{
this.notifyIcon1.Icon = m_Icon1;
m_bFlag = true;
}
}
當然先要定義三個變量:
private Icon m_Icon1;
private Icon m_Icon2;
private bool m_bFlag;
然後導入圖標文件,這兩個圖標要有差異,這樣纔能有閃爍現象
private void Form1_Load(object sender, System.EventArgs e)
{
m_bFlag=true;
m_Icon1 = new Icon("app1.ico");//導入圖標文件
m_Icon2 = new Icon("app2.ico");
this.Splashtimer.Interval = 100;
this.Splashtimer.Start();
this.Location = new System.Drawing.Point( 100 , 100 ) ;
this.Cursor = System.Windows.Forms.Cursors.Hand;
// 定義在窗體上,光標顯示爲手形
this.Text = "透明的WinForm窗體!";
// 定義窗體的標題名稱
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
// 定義窗體的開始顯示位置是屏幕的中間
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
// 窗體的邊界是Fixed3D類型
this.ForeColor = System.Drawing.SystemColors.Desktop;
//以桌面的前景色作爲窗體的前景色
this.Font = new System.Drawing.Font ( "宋體", 9 ) ;
// 定義字體類型,大小
this.BackColor = System.Drawing.Color.Blue;
// 定義背景色爲藍色
this.ClientSize = new System.Drawing.Size( 440 , 170 ) ;
// 設置窗體的大小
// Opacity屬性設立窗體的透明程度,只對於視窗2000有效
this.Opacity = 0.60 ;
}