#region ................窗体闪烁...................
[DllImport("user32.dll")] public static extern bool FlashWindow(IntPtr hWnd, bool bInvert); SoundPlayer wavPlayer = new SoundPlayer();
#endregion
#region ................窗体置顶...................
//首先要说明的是与TopMost的效果不同,TopMost是属性定义,而且设置True后,如果不设为Flase则一直置顶,效果很差, //以下方法解决了TopMost使用上的不足 //调用API [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); //获得本窗体的句柄 [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 //定义变量,句柄类型 public IntPtr Handle1;
#endregion
#region ..................窗体加载.............
private void frmMain_Load(object sender, EventArgs e) { Handle1= this.Handle; }
#endregion
FlashWindow(this.Handle, true);//闪烁 SetForegroundWindow(Handle1);//置顶
闪烁和置顶没有关联性,可单独使用!
另:Handle1 不能改,改成别的名,就不能在最顶层显示。
