From b2547d1ddc832ad1d9d3c0a36ad85dccb09dd266 Mon Sep 17 00:00:00 2001 From: YukkuriC <799433638@qq.com> Date: Mon, 4 Sep 2023 22:12:24 +0800 Subject: [PATCH] =?UTF-8?q?revert=20revert=EF=BC=88=E6=82=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Function/MWController.cs | 43 ++++++++++++++----- VPet-Simulator.Windows/MainWindow.xaml.cs | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/VPet-Simulator.Windows/Function/MWController.cs b/VPet-Simulator.Windows/Function/MWController.cs index d67b88e..e7b6dd6 100644 --- a/VPet-Simulator.Windows/Function/MWController.cs +++ b/VPet-Simulator.Windows/Function/MWController.cs @@ -1,4 +1,7 @@ -using VPet_Simulator.Core; +using System.Windows.Forms; +using System.Windows.Interop; +using System.Drawing; +using VPet_Simulator.Core; namespace VPet_Simulator.Windows { @@ -13,24 +16,43 @@ namespace VPet_Simulator.Windows this.mw = mw; } - public double GetWindowsDistanceDown() + private Rectangle? _screenBorder = null; + private Rectangle ScreenBorder { - return mw.Dispatcher.Invoke(() => System.Windows.SystemParameters.PrimaryScreenHeight - mw.Top - mw.Height); + 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); - } - - public double GetWindowsDistanceRight() - { - return mw.Dispatcher.Invoke(() => System.Windows.SystemParameters.PrimaryScreenWidth - mw.Left - mw.Width); + 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(() => ScreenBorder.Width + ScreenBorder.X - mw.Left - mw.Width); + } + + public double GetWindowsDistanceDown() + { + return mw.Dispatcher.Invoke(() => ScreenBorder.Height + ScreenBorder.Y - mw.Top - mw.Height); } public void MoveWindows(double X, double Y) @@ -39,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 5bf0f86..9931343 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -655,7 +655,7 @@ namespace VPet_Simulator.Windows Main.DisplayToNomal(); Left = (SystemParameters.PrimaryScreenWidth - Width) / 2; Top = (SystemParameters.PrimaryScreenHeight - Height) / 2; - //(Core.Controller as MWController).ClearScreenBorderCache(); + (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(); }));