From cb05e95aef8682caf7dddf8ba96eb446bdc3b52d Mon Sep 17 00:00:00 2001 From: zqm Date: Mon, 10 Nov 2025 13:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=BC=A0=E6=A0=87=E6=8C=87?= =?UTF-8?q?=E9=92=88=E4=B8=8E=E7=94=BB=E7=AC=94=E5=A4=A7=E5=B0=8F=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Setting.cs | 104 +++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index d78af59..21606c1 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -751,6 +751,7 @@ namespace JoyD.Windows.CS if (_isTempDiffDrawingMode) { // 进入温差图绘制状态 + // 暂时使用十字光标,实际光标会在MouseMove事件中根据画笔大小设置 picBoxTemp.Cursor = Cursors.Cross; btnDrawTempDiff.ToolTipText = "温差图绘制模式已启用,点击图片区域进行绘制(点击关闭)"; @@ -826,8 +827,13 @@ namespace JoyD.Windows.CS _isTempDiffDrawingMode = false; btnDrawTempDiff.Checked = false; - // 重置鼠标光标 - picBoxTemp.Cursor = Cursors.Default; + // 重置鼠标光标并释放自定义光标资源 + if (picBoxTemp.Cursor != Cursors.Default) + { + Cursor oldCursor = picBoxTemp.Cursor; + picBoxTemp.Cursor = Cursors.Default; + oldCursor.Dispose(); // 释放自定义光标资源 + } // 更新按钮提示文本 btnDrawTempDiff.ToolTipText = "绘制温差图"; @@ -997,11 +1003,105 @@ namespace JoyD.Windows.CS + /// + /// 创建与画笔大小一致的自定义光标 + /// + /// 画笔大小 + /// 画笔颜色 + /// 自定义光标 + private Cursor CreateCustomBrushCursor(int size, Color color) + { + try + { + // 创建一个足够大的位图以容纳画笔大小 + int cursorSize = Math.Max(size, 16); // 最小16x16 + Bitmap cursorBitmap = new Bitmap(cursorSize, cursorSize); + + using (Graphics g = Graphics.FromImage(cursorBitmap)) + { + // 清除背景为透明色 + g.Clear(Color.Magenta); // Magenta作为透明色 + + // 计算正方形位置,使其居中 + int x = (cursorSize - size) / 2; + int y = (cursorSize - size) / 2; + + // 绘制正方形表示画笔大小 + using (SolidBrush brush = new SolidBrush(color)) + { + g.FillRectangle(brush, x, y, size, size); + } + + // 添加边框以提高可见性 + using (Pen pen = new Pen(Color.Black)) + { + g.DrawRectangle(pen, x, y, size - 1, size - 1); + } + } + + // 设置透明色 + cursorBitmap.MakeTransparent(Color.Magenta); + + // 创建光标,热点位于正方形中心 + return new Cursor(cursorBitmap.GetHicon()); + } + catch (Exception ex) + { + Console.WriteLine("创建自定义光标失败: " + ex.Message); + // 失败时返回默认光标 + return Cursors.Cross; + } + } + /// /// 鼠标移动事件 - 更新矩形大小、移动区域、检测鼠标悬停区域或更新光标 /// private void PicBoxTemp_MouseMove(object sender, MouseEventArgs e) { + // 温差图绘制模式下,使用自定义画笔光标 + if (_isTempDiffDrawingMode) + { + // 获取当前选中的温差图例颜色 + Color selectedColor = Color.Black; // 默认颜色 + int selectedRowIndex = -1; + + // 尝试获取选中行的颜色 + if (dataGridViewTempDiff.SelectedRows.Count > 0) + { + selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index; + } + else if (dataGridViewTempDiff.SelectedCells.Count > 0) + { + selectedRowIndex = dataGridViewTempDiff.SelectedCells[0].RowIndex; + } + + // 如果选中行索引有效,获取对应的颜色 + if (selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count) + { + selectedColor = (Color)tempDiffData[selectedRowIndex]["color"]; + } + + // 创建并设置自定义光标 + Cursor customCursor = CreateCustomBrushCursor(_currentBrushSize, selectedColor); + + // 确保不重复设置相同的光标(避免资源泄漏) + if (picBoxTemp.Cursor != customCursor) + { + // 释放旧光标资源 + picBoxTemp.Cursor.Dispose(); + picBoxTemp.Cursor = customCursor; + } + + // 如果按下鼠标左键,执行绘制操作(这里可能需要根据实际绘制逻辑补充) + if (e.Button == MouseButtons.Left) + { + // 这里可以添加实际的绘制逻辑 + // 目前仅设置光标,具体绘制代码可能在其他事件中 + } + + return; // 温差图绘制模式下,不执行其他鼠标移动逻辑 + } + // 处理调整大小 if (_isResizing && !_isDrawingMode && _selectedRegionIndex != -1) {