From 291af796a6f3cdc22af4366ed047686037c43066 Mon Sep 17 00:00:00 2001 From: CCondotti Date: Tue, 18 Feb 2025 16:51:16 +0100 Subject: [PATCH 1/3] force windowState to Normal. Rename Maximize to Fill to not confuse with WindowsState, add origin Size button on demo. --- src/WpfScreenHelper/Enum/WindowPositions.cs | 2 +- src/WpfScreenHelper/WindowHelper.cs | 4 +- src/WpfScreenHelper/WpfScreenHelper.csproj | 7 +- .../MainWindow.xaml | 120 +++++++++++++++--- .../MainWindow.xaml.cs | 12 +- 5 files changed, 118 insertions(+), 27 deletions(-) diff --git a/src/WpfScreenHelper/Enum/WindowPositions.cs b/src/WpfScreenHelper/Enum/WindowPositions.cs index 3067662..c329657 100644 --- a/src/WpfScreenHelper/Enum/WindowPositions.cs +++ b/src/WpfScreenHelper/Enum/WindowPositions.cs @@ -11,6 +11,6 @@ public enum WindowPositions TopRight, BottomRight, BottomLeft, - Maximize + Fill } } diff --git a/src/WpfScreenHelper/WindowHelper.cs b/src/WpfScreenHelper/WindowHelper.cs index 9511173..5b0babb 100644 --- a/src/WpfScreenHelper/WindowHelper.cs +++ b/src/WpfScreenHelper/WindowHelper.cs @@ -20,6 +20,8 @@ public static class WindowHelper /// New height of the window. public static void SetWindowPosition(this Window window, int x, int y, int width, int height) { + //Force to normal to allow setting the window position + window.WindowState = WindowState.Normal; // The first move puts it on the correct monitor, which triggers WM_DPICHANGED // The +1/-1 coerces WPF to update Window.Top/Left/Width/Height in the second move NativeMethods.MoveWindow(new WindowInteropHelper(window).Handle, x - 1, y, width + 1, height, false); @@ -135,7 +137,7 @@ private static Rect CalculateWindowCoordinates(FrameworkElement window, WindowPo return new Rect(screen.WpfBounds.X * screen.ScaleFactor, y * screen.ScaleFactor, window.Width * screen.ScaleFactor, window.Height * screen.ScaleFactor); } - case WindowPositions.Maximize: + case WindowPositions.Fill: return new Rect(screen.WpfBounds.X * screen.ScaleFactor, screen.WpfBounds.Y * screen.ScaleFactor, screen.WpfBounds.Width * screen.ScaleFactor, screen.WpfBounds.Height * screen.ScaleFactor); default: diff --git a/src/WpfScreenHelper/WpfScreenHelper.csproj b/src/WpfScreenHelper/WpfScreenHelper.csproj index 77d41b8..6f2fd85 100644 --- a/src/WpfScreenHelper/WpfScreenHelper.csproj +++ b/src/WpfScreenHelper/WpfScreenHelper.csproj @@ -1,7 +1,7 @@ - + - net40;net6.0-windows;net8.0-windows + net40;netcoreapp3.1;net6.0-windows;net8.0-windows true true WpfScreenHelper @@ -14,7 +14,8 @@ WPF Screen Monitor Display Helper https://github.com/micdenny/WpfScreenHelper MIT - 2.1.1 + 2.2.1 + 2023.2.21.3 diff --git a/test/WpfScreenHelper.DpiTestWpfApp/MainWindow.xaml b/test/WpfScreenHelper.DpiTestWpfApp/MainWindow.xaml index 2d1835b..4254c5e 100644 --- a/test/WpfScreenHelper.DpiTestWpfApp/MainWindow.xaml +++ b/test/WpfScreenHelper.DpiTestWpfApp/MainWindow.xaml @@ -4,31 +4,111 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="MainWindow" Name="Wnd" - Height="400" Width="700" SnapsToDevicePixels="True" WindowStyle="None" ResizeMode="NoResize" - Loaded="MainWindow_OnLoaded" MouseLeftButtonDown="MainWindow_OnMouseLeftButtonDown"> + Title="MainWindow" + Name="Wnd" + Height="400" + Width="700" + SnapsToDevicePixels="True" + WindowStyle="None" + ResizeMode="NoResize" + Loaded="MainWindow_OnLoaded" + MouseLeftButtonDown="MainWindow_OnMouseLeftButtonDown"> - -