优化温差图绘制状态:1、当没有任何温差图例时隐藏删除温差图例按钮;2、当没有选定绘制时使用的温差图例时,鼠标光标不变为绘制光标且不进行绘制操作

This commit is contained in:
zqm
2025-11-11 16:54:37 +08:00
parent 491eda919b
commit 413890ef98

View File

@@ -1185,7 +1185,7 @@ namespace JoyD.Windows.CS
dataGridViewTempDiff.Visible = true; // 显示温差图例表格 dataGridViewTempDiff.Visible = true; // 显示温差图例表格
dataGridViewTempDiff.ReadOnly = false; // 温差图绘制状态下可编辑 dataGridViewTempDiff.ReadOnly = false; // 温差图绘制状态下可编辑
btnAddTempDiff.Visible = true; // 显示添加温差图例按钮 btnAddTempDiff.Visible = true; // 显示添加温差图例按钮
btnDeleteTempDiff.Visible = true; // 显示删除温差图例按钮 btnDeleteTempDiff.Visible = tempDiffData.Count > 0; // 当有温差图例时显示删除按钮
btnEraseTempDiff.Visible = true; // 显示擦除按钮 btnEraseTempDiff.Visible = true; // 显示擦除按钮
// 隐藏六个新按钮 // 隐藏六个新按钮
btnNewTempRegion.Visible = false; btnNewTempRegion.Visible = false;
@@ -1677,11 +1677,11 @@ namespace JoyD.Windows.CS
// 温差图绘制模式下,使用自定义画笔光标 // 温差图绘制模式下,使用自定义画笔光标
if (_isTempDiffDrawingMode) if (_isTempDiffDrawingMode)
{ {
// 获取当前选中的温差图例颜色 // 检查是否有选中的温差图例
Color selectedColor = Color.Black; // 默认颜色
int selectedRowIndex = -1; int selectedRowIndex = -1;
bool hasSelectedLegend = false;
// 尝试获取选中行的颜色 // 尝试获取选中行索引
if (dataGridViewTempDiff.SelectedRows.Count > 0) if (dataGridViewTempDiff.SelectedRows.Count > 0)
{ {
selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index; selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index;
@@ -1691,51 +1691,77 @@ namespace JoyD.Windows.CS
selectedRowIndex = dataGridViewTempDiff.SelectedCells[0].RowIndex; selectedRowIndex = dataGridViewTempDiff.SelectedCells[0].RowIndex;
} }
// 如果选中行索引有效,获取对应的颜色 // 检查选中行索引是否有效
if (selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count) hasSelectedLegend = selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count;
// 只有在有选中的温差图例时才设置自定义光标
if (hasSelectedLegend)
{ {
selectedColor = (Color)tempDiffData[selectedRowIndex]["color"]; // 获取当前选中的温差图例颜色
} Color selectedColor = (Color)tempDiffData[selectedRowIndex]["color"];
try
{
// 创建并设置自定义光标
Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, selectedColor);
// 确保不重复设置相同的光标(避免资源泄漏)
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 try
{ {
if (picBoxTemp.Cursor != Cursors.Cross) // 创建并设置自定义光标
Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, selectedColor);
// 确保不重复设置相同的光标(避免资源泄漏)
if (picBoxTemp.Cursor != customCursor)
{ {
picBoxTemp.Cursor = Cursors.Cross; // 获取旧光标
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
{
// 没有选中的温差图例时,使用默认光标
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 {} catch {}
} }
// 处理矩形绘制/擦除按住Ctrl键 // 处理矩形绘制/擦除按住Ctrl键- 只有在有选中的温差图例时才进行绘制
if (_isDrawingRectangle && e.Button == MouseButtons.Left && picBoxTemp.Image != null) if (_isDrawingRectangle && e.Button == MouseButtons.Left && picBoxTemp.Image != null && hasSelectedLegend)
{ {
// 获取相对于图像的当前坐标 // 获取相对于图像的当前坐标
Point currentImagePoint = ControlPointToImagePoint(e.Location); Point currentImagePoint = ControlPointToImagePoint(e.Location);
@@ -3649,8 +3675,24 @@ namespace JoyD.Windows.CS
/// </summary> /// </summary>
private void PicBoxTemp_MouseClick(object sender, MouseEventArgs e) private void PicBoxTemp_MouseClick(object sender, MouseEventArgs e)
{ {
// 温差图绘制状态下处理左键单击 // 温差图绘制状态下处理左键单击 - 只有在有选中的温差图例时才进行绘制
if (_isTempDiffDrawingMode && e.Button == MouseButtons.Left && picBoxTemp.Image != null && !_isDrawingRectangle) bool hasSelectedLegend = false;
int selectedRowIndex = -1;
// 检查是否有选中的温差图例
if (dataGridViewTempDiff.SelectedRows.Count > 0)
{
selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index;
}
else if (dataGridViewTempDiff.SelectedCells.Count > 0)
{
selectedRowIndex = dataGridViewTempDiff.SelectedCells[0].RowIndex;
}
// 检查选中行索引是否有效
hasSelectedLegend = selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count;
if (_isTempDiffDrawingMode && e.Button == MouseButtons.Left && picBoxTemp.Image != null && !_isDrawingRectangle && hasSelectedLegend)
{ {
// 初始化温差层图像(如果不存在或尺寸不匹配) // 初始化温差层图像(如果不存在或尺寸不匹配)
if (_tempDiffOverlayImage == null || if (_tempDiffOverlayImage == null ||