修复擦除时笔块大小与视觉光标块大小不一致的问题,确保在擦除模式下光标大小随画笔大小同步更新
This commit is contained in:
@@ -146,20 +146,102 @@ namespace JoyD.Windows.CS
|
||||
/// 10像素画笔大小按钮点击事件
|
||||
/// </summary>
|
||||
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 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 15像素画笔大小按钮点击事件
|
||||
/// </summary>
|
||||
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 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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 {}
|
||||
}
|
||||
|
||||
// 重置上一个绘制点,确保下一次绘制/擦除是新的起点
|
||||
|
||||
Reference in New Issue
Block a user