From 5ad7b76e3bd1606bfb13dc1a2b554544ae1d4884 Mon Sep 17 00:00:00 2001 From: zqm Date: Tue, 11 Nov 2025 09:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=93=A6=E9=99=A4=E6=97=B6?= =?UTF-8?q?=E7=AC=94=E5=9D=97=E5=A4=A7=E5=B0=8F=E4=B8=8E=E8=A7=86=E8=A7=89?= =?UTF-8?q?=E5=85=89=E6=A0=87=E5=9D=97=E5=A4=A7=E5=B0=8F=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=9C=A8=E6=93=A6=E9=99=A4=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=85=89?= =?UTF-8?q?=E6=A0=87=E5=A4=A7=E5=B0=8F=E9=9A=8F=E7=94=BB=E7=AC=94=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Setting.cs | 185 +++++++++++++++++- 1 file changed, 182 insertions(+), 3 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index bb16fb4..f2a9805 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -146,20 +146,102 @@ namespace JoyD.Windows.CS /// 10像素画笔大小按钮点击事件 /// private void BtnBrushSize10_Click(object sender, EventArgs e) - { + { _currentBrushSize = 10; // 更新按钮选中状态 UpdateBrushSizeButtonSelection(10); + + // 如果当前是擦除模式,更新光标大小 + if (_isEraseMode) + { + try + { + // 使用白色作为擦除模式的光标颜色,以便在各种背景下都可见 + Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, Color.White); + + // 确保不重复设置相同的光标(避免资源泄漏) + if (picBoxTemp.Cursor != customCursor) + { + // 获取旧光标 + Cursor oldCursor = picBoxTemp.Cursor; + + // 先设置新光标 + picBoxTemp.Cursor = customCursor; + + // 只释放自定义光标,不释放系统光标 + if (oldCursor != null && oldCursor != Cursors.Default && + oldCursor != Cursors.Cross && oldCursor != Cursors.Hand && + oldCursor != Cursors.IBeam && oldCursor != Cursors.WaitCursor) + { + oldCursor.Dispose(); + } + } + } + catch (Exception ex) + { + Console.WriteLine("更新擦除模式光标大小时发生异常: " + ex.Message); + // 出现异常时设置为十字光标 + try + { + if (picBoxTemp.Cursor != Cursors.Cross) + { + picBoxTemp.Cursor = Cursors.Cross; + } + } + catch {} + } + } } /// /// 15像素画笔大小按钮点击事件 /// private void BtnBrushSize15_Click(object sender, EventArgs e) - { + { _currentBrushSize = 15; // 更新按钮选中状态 UpdateBrushSizeButtonSelection(15); + + // 如果当前是擦除模式,更新光标大小 + if (_isEraseMode) + { + try + { + // 使用白色作为擦除模式的光标颜色,以便在各种背景下都可见 + Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, Color.White); + + // 确保不重复设置相同的光标(避免资源泄漏) + if (picBoxTemp.Cursor != customCursor) + { + // 获取旧光标 + Cursor oldCursor = picBoxTemp.Cursor; + + // 先设置新光标 + picBoxTemp.Cursor = customCursor; + + // 只释放自定义光标,不释放系统光标 + if (oldCursor != null && oldCursor != Cursors.Default && + oldCursor != Cursors.Cross && oldCursor != Cursors.Hand && + oldCursor != Cursors.IBeam && oldCursor != Cursors.WaitCursor) + { + oldCursor.Dispose(); + } + } + } + catch (Exception ex) + { + Console.WriteLine("更新擦除模式光标大小时发生异常: " + ex.Message); + // 出现异常时设置为十字光标 + try + { + if (picBoxTemp.Cursor != Cursors.Cross) + { + picBoxTemp.Cursor = Cursors.Cross; + } + } + catch {} + } + } } /// @@ -170,6 +252,47 @@ namespace JoyD.Windows.CS _currentBrushSize = 25; // 更新按钮选中状态 UpdateBrushSizeButtonSelection(25); + + // 如果当前是擦除模式,更新光标大小 + if (_isEraseMode) + { + try + { + // 使用白色作为擦除模式的光标颜色,以便在各种背景下都可见 + Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, Color.White); + + // 确保不重复设置相同的光标(避免资源泄漏) + if (picBoxTemp.Cursor != customCursor) + { + // 获取旧光标 + Cursor oldCursor = picBoxTemp.Cursor; + + // 先设置新光标 + picBoxTemp.Cursor = customCursor; + + // 只释放自定义光标,不释放系统光标 + if (oldCursor != null && oldCursor != Cursors.Default && + oldCursor != Cursors.Cross && oldCursor != Cursors.Hand && + oldCursor != Cursors.IBeam && oldCursor != Cursors.WaitCursor) + { + oldCursor.Dispose(); + } + } + } + catch (Exception ex) + { + Console.WriteLine("更新擦除模式光标大小时发生异常: " + ex.Message); + // 出现异常时设置为十字光标 + try + { + if (picBoxTemp.Cursor != Cursors.Cross) + { + picBoxTemp.Cursor = Cursors.Cross; + } + } + catch {} + } + } } /// @@ -186,10 +309,66 @@ namespace JoyD.Windows.CS if (_isEraseMode) { btnEraseTempDiff.ToolTipText = "擦除模式已启用,点击图片区域进行擦除(点击关闭)"; - } + + // 在擦除模式下,更新光标以匹配当前画笔大小 + try + { + // 使用白色作为擦除模式的光标颜色,以便在各种背景下都可见 + Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, Color.White); + + // 确保不重复设置相同的光标(避免资源泄漏) + if (picBoxTemp.Cursor != customCursor) + { + // 获取旧光标 + Cursor oldCursor = picBoxTemp.Cursor; + + // 先设置新光标 + picBoxTemp.Cursor = customCursor; + + // 只释放自定义光标,不释放系统光标 + if (oldCursor != null && oldCursor != Cursors.Default && + oldCursor != Cursors.Cross && oldCursor != Cursors.Hand && + oldCursor != Cursors.IBeam && oldCursor != Cursors.WaitCursor) + { + oldCursor.Dispose(); + } + } + } + catch (Exception ex) + { + Console.WriteLine("设置擦除模式光标时发生异常: " + ex.Message); + // 出现异常时设置为十字光标 + try + { + if (picBoxTemp.Cursor != Cursors.Cross) + { + picBoxTemp.Cursor = Cursors.Cross; + } + } + catch {} + } + } else { btnEraseTempDiff.ToolTipText = "使用透明色擦除温差图"; + // 退出擦除模式时,可以恢复默认光标或其他光标 + try + { + if (picBoxTemp.Cursor != Cursors.Default) + { + Cursor oldCursor = picBoxTemp.Cursor; + picBoxTemp.Cursor = Cursors.Default; + + // 只释放自定义光标,不释放系统光标 + if (oldCursor != null && oldCursor != Cursors.Default && + oldCursor != Cursors.Cross && oldCursor != Cursors.Hand && + oldCursor != Cursors.IBeam && oldCursor != Cursors.WaitCursor) + { + oldCursor.Dispose(); + } + } + } + catch {} } // 重置上一个绘制点,确保下一次绘制/擦除是新的起点