设置窗口在最前

[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)
private static extern bool SetForegroundWindow(IntPtr hWnd);

private const int SW_SHOWNORMAL = 1;//正常大小窗口

void FixedTop()
{
    IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;//获取应用程序句柄
    ShowWindowAsync(hwnd, SW_SHOWNORMAL);//确保窗口没有被最小化或最大化
    SetForegroundWindow(hwnd);//设置应用程序为前台,返回bool值。
}
原文地址:https://www.cnblogs.com/springsnow/p/9433922.html