private void MoveToCenterWithGaps() { IntPtr activeWindow = GetForegroundWindow(); GetWindowRect(activeWindow, out SystemRect windowRect); var workingArea = GetMonitorNumber(ToRectangle(windowRect)); int screenWidth = workingArea.Width; int screenHeight = workingArea.Height; string percentageText = "0.95"; if (double.TryParse(percentageText, out double result)) { SystemRect rect = _screenCalculator.ChangeWindowSize(screenWidth, screenHeight, result, result); var windowWidth = _screenCalculator.ComputeForWindowLength(rect.Right, rect.Left); var windowHeight = _screenCalculator.ComputeForWindowLength(rect.Bottom, rect.Top); int x = _screenCalculator.ComputeForX(screenWidth, rect, workingArea.X); int y = _screenCalculator.ComputeForY(screenHeight, rect, workingArea.Y); System.Diagnostics.Debug.WriteLine($"x: {x} / y: {y} / windowWidth: {windowWidth} / windowHeight: {windowHeight}"); SetWindowPos(GetForegroundWindow(), (IntPtr)SpecialWindowHandles.HWND_TOP, x, y, windowWidth, windowHeight, SetWindowPosFlags.SWP_SHOWWINDOW); } }
public Rectangle ToRectangle(SystemRect systemRect) { return(new Rectangle { Width = systemRect.Right - systemRect.Left, Height = systemRect.Bottom - systemRect.Top, X = systemRect.Left, Y = systemRect.Top, Location = new Point(systemRect.Left, systemRect.Top), Size = new Size(systemRect.Right - systemRect.Left, systemRect.Bottom - systemRect.Top) }); }
private static extern bool GetWindowRect(IntPtr hWnd, out SystemRect rect);