[DllImport("userdll" CharSet = CharSetAuto)]
private static extern int SetWindowPos(IntPtr hWnd int hWndInsertAfter int x int y int Width int Height int flags);
/// <summary>
/// 得到当前活动的窗口
/// </summary>
/// <returns></returns>
[DllImport("userdll" CharSet = CharSetAuto)]
private static extern SystemIntPtr GetForegroundWindow();
哪个窗体想要置顶在Form_Load中加上
SetWindowPos(thisHandle | ); //最后参数也有用 |
具体说明看API函数说明
如果是用点击一个按钮后弹出新窗体并置顶则
Form frm = new Form();
frmShow();
SetWindowPos(GetForegroundWindow() | );