From 74eca093da11eb7b9b07ccf36bc9862ded019f04 Mon Sep 17 00:00:00 2001 From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com> Date: Sun, 2 Nov 2025 11:40:27 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E6=82=AC=E6=B5=AE=E5=BF=AB=E6=8A=BD?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Windows/QuickDrawFloatingButton.cs | 69 ++++++++++++++++++ .../Windows/QuickDrawFloatingButton.xaml | 71 +++++++++++++++---- 2 files changed, 127 insertions(+), 13 deletions(-) diff --git a/Ink Canvas/Windows/QuickDrawFloatingButton.cs b/Ink Canvas/Windows/QuickDrawFloatingButton.cs index 6c5360bd..61aebc2f 100644 --- a/Ink Canvas/Windows/QuickDrawFloatingButton.cs +++ b/Ink Canvas/Windows/QuickDrawFloatingButton.cs @@ -14,6 +14,10 @@ namespace Ink_Canvas /// public partial class QuickDrawFloatingButton : Window { + private bool isDragging = false; + private Point dragStartPoint; + private Point windowStartPoint; + public QuickDrawFloatingButton() { InitializeComponent(); @@ -62,6 +66,9 @@ namespace Ink_Canvas { try { + // 如果正在拖动,不触发点击事件 + if (isDragging) return; + // 打开快抽窗口 var quickDrawWindow = new QuickDrawWindow(); quickDrawWindow.ShowDialog(); @@ -72,6 +79,68 @@ namespace Ink_Canvas } } + private void DragArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + isDragging = false; + // 记录鼠标在屏幕上的初始位置 + dragStartPoint = this.PointToScreen(e.GetPosition(this)); + // 记录窗口的初始位置 + windowStartPoint = new Point(this.Left, this.Top); + ((UIElement)sender).CaptureMouse(); + e.Handled = true; + } + + private void DragArea_MouseMove(object sender, MouseEventArgs e) + { + if (e.LeftButton == MouseButtonState.Pressed && ((UIElement)sender).IsMouseCaptured) + { + // 获取鼠标在屏幕上的当前位置 + Point currentScreenPoint = this.PointToScreen(e.GetPosition(this)); + Vector diff = currentScreenPoint - dragStartPoint; + + if (!isDragging && (Math.Abs(diff.X) > 3 || Math.Abs(diff.Y) > 3)) + { + isDragging = true; + } + + if (isDragging) + { + // 使用窗口初始位置加上鼠标移动的距离 + double newLeft = windowStartPoint.X + diff.X; + double newTop = windowStartPoint.Y + diff.Y; + + // 限制在屏幕范围内 + var workingArea = SystemParameters.WorkArea; + newLeft = Math.Max(workingArea.Left, Math.Min(newLeft, workingArea.Right - this.Width)); + newTop = Math.Max(workingArea.Top, Math.Min(newTop, workingArea.Bottom - this.Height)); + + this.Left = newLeft; + this.Top = newTop; + } + } + } + + private void DragArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + if (((UIElement)sender).IsMouseCaptured) + { + ((UIElement)sender).ReleaseMouseCapture(); + } + + // 延迟重置拖动状态,避免触发点击事件 + if (isDragging) + { + Dispatcher.BeginInvoke(new Action(() => { isDragging = false; }), + DispatcherPriority.Background); + } + else + { + isDragging = false; + } + + e.Handled = true; + } + diff --git a/Ink Canvas/Windows/QuickDrawFloatingButton.xaml b/Ink Canvas/Windows/QuickDrawFloatingButton.xaml index d743c383..07786911 100644 --- a/Ink Canvas/Windows/QuickDrawFloatingButton.xaml +++ b/Ink Canvas/Windows/QuickDrawFloatingButton.xaml @@ -7,7 +7,7 @@ mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Loaded="FloatingButton_Loaded" WindowStartupLocation="Manual" ShowInTaskbar="False" Focusable="False" - Title="快抽悬浮按钮" Height="45" Width="45"> + Title="快抽悬浮按钮" Height="45" Width="65"> @@ -21,23 +21,68 @@ + BorderBrush="{DynamicResource QuickDrawFloatingButtonBorderBrush}"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +