我有一个Windows应用程序(我正在用C#编写)以无界限的最大化窗口开始。SetWindowPos每次都将窗口移动到不同的位置
当用户点击应用程序中的按钮时,我想恢复窗口(即删除最大化状态),将其调整到一定大小并将其移动到屏幕的右下角。
我的问题是,调用SetWindowPos()
时,正确调整窗口大小并不总是将它放在屏幕的右下角。有时候它确实存在,但有些时候窗口放置在屏幕的其他位置(就好像它“跳跃”一样,出于我忽略的原因)。
我在做什么错?
这是我的代码。请注意,我将-1作为第二个参数传递给SetWindowPos,因为我希望我的窗口位于其他窗口之上。
public void MoveAppWindowToBottomRight()
{
Process process = Process.GetCurrentProcess();
IntPtr handler = process.MainWindowHandle;
ShowWindow(handler, 9); // SW_RESTORE = 9
int x = (int)(System.Windows.SystemParameters.PrimaryScreenWidth - 380);
int y = (int)(System.Windows.SystemParameters.PrimaryScreenHeight - 250);
NativePoint point = new NativePoint { x = x, y = y };
ClientToScreen(handler, ref point);
SetWindowPos(handler, -1, point.x, point.y, 380, 250, 0);
}
[StructLayout(LayoutKind.Sequential)]
public struct NativePoint
{
public int x;
public int y;
}
[SystemParameters.PrimaryScreenWidth](https://msdn.microsoft.com /en-us/library/system.windows.systemparameters.primaryscreenwidth.aspx)和[SystemParameters.PrimaryScreenHeight](https://msdn.microsoft.com/en-us/library/system.windows.systemparameters.primaryscreenheight.aspx)不要占用任务栏占用的空间。这与这个问题的问题无关。这是你需要解决的另一个bug。 – IInspectable