优化温差图绘制状态:1、当没有任何温差图例时隐藏删除温差图例按钮;2、当没有选定绘制时使用的温差图例时,鼠标光标不变为绘制光标且不进行绘制操作
This commit is contained in:
@@ -1185,7 +1185,7 @@ namespace JoyD.Windows.CS
|
||||
dataGridViewTempDiff.Visible = true; // 显示温差图例表格
|
||||
dataGridViewTempDiff.ReadOnly = false; // 温差图绘制状态下可编辑
|
||||
btnAddTempDiff.Visible = true; // 显示添加温差图例按钮
|
||||
btnDeleteTempDiff.Visible = true; // 显示删除温差图例按钮
|
||||
btnDeleteTempDiff.Visible = tempDiffData.Count > 0; // 当有温差图例时显示删除按钮
|
||||
btnEraseTempDiff.Visible = true; // 显示擦除按钮
|
||||
// 隐藏六个新按钮
|
||||
btnNewTempRegion.Visible = false;
|
||||
@@ -1677,11 +1677,11 @@ namespace JoyD.Windows.CS
|
||||
// 温差图绘制模式下,使用自定义画笔光标
|
||||
if (_isTempDiffDrawingMode)
|
||||
{
|
||||
// 获取当前选中的温差图例颜色
|
||||
Color selectedColor = Color.Black; // 默认颜色
|
||||
// 检查是否有选中的温差图例
|
||||
int selectedRowIndex = -1;
|
||||
bool hasSelectedLegend = false;
|
||||
|
||||
// 尝试获取选中行的颜色
|
||||
// 尝试获取选中行索引
|
||||
if (dataGridViewTempDiff.SelectedRows.Count > 0)
|
||||
{
|
||||
selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index;
|
||||
@@ -1691,51 +1691,77 @@ namespace JoyD.Windows.CS
|
||||
selectedRowIndex = dataGridViewTempDiff.SelectedCells[0].RowIndex;
|
||||
}
|
||||
|
||||
// 如果选中行索引有效,获取对应的颜色
|
||||
if (selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count)
|
||||
{
|
||||
selectedColor = (Color)tempDiffData[selectedRowIndex]["color"];
|
||||
}
|
||||
// 检查选中行索引是否有效
|
||||
hasSelectedLegend = selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count;
|
||||
|
||||
try
|
||||
// 只有在有选中的温差图例时才设置自定义光标
|
||||
if (hasSelectedLegend)
|
||||
{
|
||||
// 创建并设置自定义光标
|
||||
Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, selectedColor);
|
||||
// 获取当前选中的温差图例颜色
|
||||
Color selectedColor = (Color)tempDiffData[selectedRowIndex]["color"];
|
||||
|
||||
// 确保不重复设置相同的光标(避免资源泄漏)
|
||||
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)
|
||||
// 创建并设置自定义光标
|
||||
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 {}
|
||||
}
|
||||
|
||||
// 处理矩形绘制/擦除(按住Ctrl键)
|
||||
if (_isDrawingRectangle && e.Button == MouseButtons.Left && picBoxTemp.Image != null)
|
||||
// 处理矩形绘制/擦除(按住Ctrl键)- 只有在有选中的温差图例时才进行绘制
|
||||
if (_isDrawingRectangle && e.Button == MouseButtons.Left && picBoxTemp.Image != null && hasSelectedLegend)
|
||||
{
|
||||
// 获取相对于图像的当前坐标
|
||||
Point currentImagePoint = ControlPointToImagePoint(e.Location);
|
||||
@@ -3649,8 +3675,24 @@ namespace JoyD.Windows.CS
|
||||
/// </summary>
|
||||
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 ||
|
||||
|
||||
Reference in New Issue
Block a user