調用WindowsAPI使窗體始終保持置頂效果,不被其他窗體遮蓋: 使用方式:在需要置頂的窗體的Load方法裡面加上 ...
調用WindowsAPI使窗體始終保持置頂效果,不被其他窗體遮蓋:
[DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags); /// <summary> /// 得到當前活動的視窗 /// </summary> /// <returns></returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern System.IntPtr GetForegroundWindow();
使用方式:在需要置頂的窗體的Load方法裡面加上
//Load private void Form1_Load(object sender, EventArgs e) { try { SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); } catch (Exception ex) { MessageBox.Show(ex.Message); } //3764 }