C# 如何讓任務欄上的窗口閃動起來

1、導入動態庫方法:

[System.Runtime.InteropServices.DllImport("USER32.DLL")]
public static extern int FlashWindow(int hwnd, int iStart);

//hwnd : 控件的句柄實例值
//iStart : 參數爲1時啓動閃爍, 參數爲0時停止閃爍 

2、使用動態庫函數:
FlashWindow(this.Handle.ToInt32(), 1); // 參數爲1時啓動閃爍, 參數爲0時停止閃爍 
//this : 表示Form窗口

3、定時器進行閃動(在窗口加載事件中添加如下內容):

Timer timer = new Timer();
timer.Interval = 200;
timer.Enabled = true;
timer.Tick += delegate {
   FlashWindow(this.Handle.ToInt32(), 1);
};


4、運行項目即可(F5)。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章