From 77843f65117969179626271b67b5be4c809ea85f Mon Sep 17 00:00:00 2001 From: YukkuriC <799433638@qq.com> Date: Mon, 28 Aug 2023 22:25:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B1=8F=E5=B9=95=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E8=AE=A1=E7=AE=97+=E7=BC=93=E5=AD=98=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E5=A4=96=E5=8C=85=E7=9F=A9=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Function/MWController.cs | 41 +++++++++++-------- VPet-Simulator.Windows/MainWindow.xaml.cs | 1 + 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/VPet-Simulator.Windows/Function/MWController.cs b/VPet-Simulator.Windows/Function/MWController.cs index 43ef9df..e7b6dd6 100644 --- a/VPet-Simulator.Windows/Function/MWController.cs +++ b/VPet-Simulator.Windows/Function/MWController.cs @@ -1,5 +1,6 @@ using System.Windows.Forms; using System.Windows.Interop; +using System.Drawing; using VPet_Simulator.Core; namespace VPet_Simulator.Windows @@ -15,36 +16,43 @@ namespace VPet_Simulator.Windows this.mw = mw; } + private Rectangle? _screenBorder = null; + private Rectangle ScreenBorder + { + get + { + if (_screenBorder == null) + { + var windowInteropHelper = new WindowInteropHelper(mw); + var currentScreen = Screen.FromHandle(windowInteropHelper.Handle); + _screenBorder = currentScreen.Bounds; + } + return (Rectangle)_screenBorder; + } + } + public void ClearScreenBorderCache() + { + _screenBorder = null; + } + public double GetWindowsDistanceLeft() { - return mw.Dispatcher.Invoke(() => mw.Left); + return mw.Dispatcher.Invoke(() => mw.Left - ScreenBorder.X); } public double GetWindowsDistanceUp() { - return mw.Dispatcher.Invoke(() => mw.Top); + return mw.Dispatcher.Invoke(() => mw.Top - ScreenBorder.Y); } public double GetWindowsDistanceRight() { - return mw.Dispatcher.Invoke(() => - { - var windowInteropHelper = new WindowInteropHelper(mw); - var currentScreen = Screen.FromHandle(windowInteropHelper.Handle); - var currentScreenBorder = currentScreen.Bounds; - return currentScreenBorder.Width - mw.Left - mw.Width; - }); + return mw.Dispatcher.Invoke(() => ScreenBorder.Width + ScreenBorder.X - mw.Left - mw.Width); } public double GetWindowsDistanceDown() { - return mw.Dispatcher.Invoke(() => - { - var windowInteropHelper = new WindowInteropHelper(mw); - var currentScreen = Screen.FromHandle(windowInteropHelper.Handle); - var currentScreenBorder = currentScreen.Bounds; - return currentScreenBorder.Height - mw.Top - mw.Height; - }); + return mw.Dispatcher.Invoke(() => ScreenBorder.Height + ScreenBorder.Y - mw.Top - mw.Height); } public void MoveWindows(double X, double Y) @@ -53,6 +61,7 @@ namespace VPet_Simulator.Windows { mw.Left += X * ZoomRatio; mw.Top += Y * ZoomRatio; + ClearScreenBorderCache(); }); } diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index c1016d2..cc09ade 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -638,6 +638,7 @@ namespace VPet_Simulator.Windows Main.DisplayToNomal(); Left = (SystemParameters.PrimaryScreenWidth - Width) / 2; Top = (SystemParameters.PrimaryScreenHeight - Height) / 2; + (Core.Controller as MWController).ClearScreenBorderCache(); })); m_menu.MenuItems.Add(new MenuItem("反馈中心".Translate(), (x, y) => { new winReport(this).Show(); })); m_menu.MenuItems.Add(new MenuItem("开发控制台".Translate(), (x, y) => { new winConsole(this).Show(); }));