From 40ecfbefa301d0f8eaa35fa07c55f00399ef4b56 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 31 Aug 2025 10:47:33 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E6=88=AA=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Windows/ScreenshotSelectorWindow.xaml | 14 ++- .../Windows/ScreenshotSelectorWindow.xaml.cs | 92 ++++++++++++++++++- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml index d82fcbd6..c811439e 100644 --- a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml +++ b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml @@ -18,12 +18,14 @@ + Opacity="0.3" + IsHitTestVisible="False" /> @@ -43,8 +45,14 @@ + Fill="#01FFFFFF" + Visibility="Collapsed" + IsHitTestVisible="True" + Panel.ZIndex="1001" + MouseLeftButtonDown="SelectionRectangle_MouseLeftButtonDown" + MouseLeftButtonUp="SelectionRectangle_MouseLeftButtonUp" + MouseMove="SelectionRectangle_MouseMove" + Cursor="SizeAll" /> screenBounds.Right) newRect.X = screenBounds.Right - newRect.Width; + if (newRect.Bottom > screenBounds.Bottom) newRect.Y = screenBounds.Bottom - newRect.Height; + + _currentSelection = newRect; + UpdateSelectionDisplay(); + + _lastMousePosition = currentPosition; + e.Handled = true; + + // 添加调试信息 + System.Diagnostics.Debug.WriteLine($"SelectionRectangle moving: delta=({delta.X}, {delta.Y}), newRect=({newRect.X}, {newRect.Y}, {newRect.Width}, {newRect.Height})"); + } + catch (Exception ex) + { + // 如果出现异常,停止移动 + System.Diagnostics.Debug.WriteLine($"SelectionRectangle move error: {ex.Message}"); + _isMoving = false; + _activeControlPoint = ControlPointType.None; + SelectionRectangle.ReleaseMouseCapture(); + } + } + + private void SelectionRectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + if (_isMoving && _activeControlPoint == ControlPointType.Move) + { + _isMoving = false; + _activeControlPoint = ControlPointType.None; + SelectionRectangle.ReleaseMouseCapture(); + e.Handled = true; + } + } + private void ResetSelectionState() { // 重置所有选择相关的状态 @@ -724,6 +808,12 @@ namespace Ink_Canvas ReleaseMouseCapture(); } + // 释放选择矩形的鼠标捕获 + if (SelectionRectangle.IsMouseCaptured) + { + SelectionRectangle.ReleaseMouseCapture(); + } + // 重置选择区域 _currentSelection = new Rect(); SelectedArea = null;