private void RecalculateSystemScale() { DpiUtilities.GetSystemEffectiveDpi(out _systemDpiX, out _systemDpiY); SystemScale = DpiUtilities.CalculateScale(_systemDpiX, _systemDpiY, 96, 96); #if (DEBUG) System.Diagnostics.Debug.WriteLine("System DPI = " + _systemDpiX.ToString()); #endif }
private void RecalculateMonitorScale() { uint dpiX; uint dpiY; DpiUtilities.GetWindowEffectiveDpi(_hwnd, out dpiX, out dpiY); if (dpiX != lastDpiX && dpiY != lastDpiY) { VirtualPixelScale = DpiUtilities.CalculateScale(dpiX, dpiY, 96, 96); lastDpiX = dpiX; lastDpiY = dpiY; } }
public static void PositionWindowOnScreenWithOffsetIgnoringSystemDPI(Window window, System.Windows.Forms.Screen screen, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, float hOffset, float vOffset) { System.IntPtr monitor = NativeMethods.GetMonitorFromWindow(NativeMethods.GetWindowHwnd(window)); var _screenProps = new ScreenProperties(); _screenProps.GetMonitorsInformation(); var monitorInfo = _screenProps.GetMonitorInformation(monitor); var workingArea = monitorInfo.rcWork; var dpiScale = DpiUtilities.CalculateScale((uint)monitorInfo.dpiX, (uint)monitorInfo.dpiY, 96, 96); double workingLeft = (workingArea.left + hOffset) / dpiScale.X; double workingWidth = workingArea.width / dpiScale.X; double workingTop = (workingArea.top + vOffset) / dpiScale.Y; double workingHeight = workingArea.height / dpiScale.Y; PositionWindow(window, workingLeft, workingTop, workingWidth, workingHeight, horizontalAlignment, verticalAlignment); }