From c80647fc17f5819e0782c652380592bd05aa700a Mon Sep 17 00:00:00 2001 From: cccccchara <2579505963@qq.com> Date: Sun, 21 Apr 2024 01:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BC=A9=E6=94=BE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=80=89=E6=8B=A9=E5=BD=93=E5=89=8D=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinDesign/winGameSetting.xaml.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs index 6246bc8..c9ad5d5 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs @@ -758,7 +758,28 @@ namespace VPet_Simulator.Windows var windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(mw); var currentScreen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle); var mwCtrl = mw.Core.Controller as MWController; - mwCtrl.ScreenBorder = currentScreen.Bounds; + + // 获取窗口的 DPI 信息 + var hwndSource = System.Windows.Interop.HwndSource.FromHwnd(windowInteropHelper.Handle); + if (hwndSource != null && hwndSource.CompositionTarget != null) + { + var dpiScale = hwndSource.CompositionTarget.TransformToDevice; + + // 使用 DPI 缩放调整当前屏幕的边界,然后将其转换为整数坐标的矩形 + var dpiAdjustedBounds = new System.Drawing.Rectangle( + (int)(currentScreen.Bounds.X / dpiScale.M11), + (int)(currentScreen.Bounds.Y / dpiScale.M22), + (int)(currentScreen.Bounds.Width / dpiScale.M11), + (int)(currentScreen.Bounds.Height / dpiScale.M22)); + if (mwCtrl != null) + mwCtrl.ScreenBorder = dpiAdjustedBounds; + } + else + { + if (mwCtrl != null) + // 如果无法获取 DPI 信息,回退到未调整的边界 + mwCtrl.ScreenBorder = currentScreen.Bounds; + } UpdateMoveAreaText(); }