From 413890ef98fa42f74dbb3163a1b54b182b2335dc Mon Sep 17 00:00:00 2001 From: zqm Date: Tue, 11 Nov 2025 16:54:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B8=A9=E5=B7=AE=E5=9B=BE?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E7=8A=B6=E6=80=81=EF=BC=9A1=E3=80=81?= =?UTF-8?q?=E5=BD=93=E6=B2=A1=E6=9C=89=E4=BB=BB=E4=BD=95=E6=B8=A9=E5=B7=AE?= =?UTF-8?q?=E5=9B=BE=E4=BE=8B=E6=97=B6=E9=9A=90=E8=97=8F=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=B8=A9=E5=B7=AE=E5=9B=BE=E4=BE=8B=E6=8C=89=E9=92=AE=EF=BC=9B?= =?UTF-8?q?2=E3=80=81=E5=BD=93=E6=B2=A1=E6=9C=89=E9=80=89=E5=AE=9A?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E6=97=B6=E4=BD=BF=E7=94=A8=E7=9A=84=E6=B8=A9?= =?UTF-8?q?=E5=B7=AE=E5=9B=BE=E4=BE=8B=E6=97=B6=EF=BC=8C=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E5=85=89=E6=A0=87=E4=B8=8D=E5=8F=98=E4=B8=BA=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E5=85=89=E6=A0=87=E4=B8=94=E4=B8=8D=E8=BF=9B=E8=A1=8C=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Setting.cs | 122 ++++++++++++------ 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index 452b21d..3a920fa 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -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 /// 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 ||