[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值。 }