From ead0854c8e4fb80cf8131ff32f0b526712ed390a Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 7 Sep 2025 07:59:21 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E5=A2=A8=E8=BF=B9=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainWindow_cs/MW_SelectionGestures.cs | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs index 26813344..402e51b0 100644 --- a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs +++ b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs @@ -875,48 +875,55 @@ namespace Ink_Canvas private Rect CalculateNewBounds(Rect originalBounds, Point delta, string handleName) { var newBounds = originalBounds; + double newWidth = originalBounds.Width; + double newHeight = originalBounds.Height; + double newX = originalBounds.X; + double newY = originalBounds.Y; switch (handleName) { case "TopLeftHandle": - newBounds.X = originalBounds.X + delta.X; - newBounds.Y = originalBounds.Y + delta.Y; - newBounds.Width = originalBounds.Width - delta.X; - newBounds.Height = originalBounds.Height - delta.Y; + newX = originalBounds.X + delta.X; + newY = originalBounds.Y + delta.Y; + newWidth = originalBounds.Width - delta.X; + newHeight = originalBounds.Height - delta.Y; break; case "TopRightHandle": - newBounds.Y = originalBounds.Y + delta.Y; - newBounds.Width = originalBounds.Width + delta.X; - newBounds.Height = originalBounds.Height - delta.Y; + newY = originalBounds.Y + delta.Y; + newWidth = originalBounds.Width + delta.X; + newHeight = originalBounds.Height - delta.Y; break; case "BottomLeftHandle": - newBounds.X = originalBounds.X + delta.X; - newBounds.Width = originalBounds.Width - delta.X; - newBounds.Height = originalBounds.Height + delta.Y; + newX = originalBounds.X + delta.X; + newWidth = originalBounds.Width - delta.X; + newHeight = originalBounds.Height + delta.Y; break; case "BottomRightHandle": - newBounds.Width = originalBounds.Width + delta.X; - newBounds.Height = originalBounds.Height + delta.Y; + newWidth = originalBounds.Width + delta.X; + newHeight = originalBounds.Height + delta.Y; break; case "TopHandle": - newBounds.Y = originalBounds.Y + delta.Y; - newBounds.Height = originalBounds.Height - delta.Y; + newY = originalBounds.Y + delta.Y; + newHeight = originalBounds.Height - delta.Y; break; case "BottomHandle": - newBounds.Height = originalBounds.Height + delta.Y; + newHeight = originalBounds.Height + delta.Y; break; case "LeftHandle": - newBounds.X = originalBounds.X + delta.X; - newBounds.Width = originalBounds.Width - delta.X; + newX = originalBounds.X + delta.X; + newWidth = originalBounds.Width - delta.X; break; case "RightHandle": - newBounds.Width = originalBounds.Width + delta.X; + newWidth = originalBounds.Width + delta.X; break; } - // 确保最小尺寸 - if (newBounds.Width < 10) newBounds.Width = 10; - if (newBounds.Height < 10) newBounds.Height = 10; + // 确保最小尺寸和正值 + if (newWidth < 10) newWidth = 10; + if (newHeight < 10) newHeight = 10; + + // 创建新的Rect,确保所有值都是有效的 + newBounds = new Rect(newX, newY, newWidth, newHeight); return newBounds; }