From fa121f4ab8689cef88cc773a57fcc6119d4925b3 Mon Sep 17 00:00:00 2001 From: XingCheng3 <1773407212@qq.com> Date: Wed, 13 May 2026 01:35:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E7=A7=B0=E9=87=8D?= =?UTF-8?q?=E5=88=86=E6=9E=90=20=E7=82=B9=E4=BD=8DTip=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=82=B9=E4=BD=8D=E8=AF=A6=E7=BB=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SCADA/Pages/UC_WeighingAnalysis.cs | 70 ++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/SCADA/Pages/UC_WeighingAnalysis.cs b/SCADA/Pages/UC_WeighingAnalysis.cs index b1183d2..2bb8f88 100644 --- a/SCADA/Pages/UC_WeighingAnalysis.cs +++ b/SCADA/Pages/UC_WeighingAnalysis.cs @@ -35,12 +35,15 @@ namespace MesWork.Pages private readonly Label lbl_Product = new Label(); private readonly Label lbl_Sample = new Label(); private readonly Label lbl_Status = new Label(); + private readonly ToolTip tip_Point = new ToolTip(); private readonly List _points = new List(); + private PointF[] _chartPoints = new PointF[0]; private int _finalStartSeq; private int _finalEndSeq; private decimal? _finalWeight; private int _sampleIntervalMs; + private int _lastTipSeq; private static readonly Color ClrPrimary = Color.FromArgb(74, 144, 217); private static readonly Color ClrPrimaryDark = Color.FromArgb(30, 58, 95); @@ -61,6 +64,8 @@ namespace MesWork.Pages SetHint(txt_OrderNo, "工单号..."); pnl_Chart.Paint += pnl_Chart_Paint; pnl_Chart.Resize += (s, e) => pnl_Chart.Invalidate(); + pnl_Chart.MouseMove += pnl_Chart_MouseMove; + pnl_Chart.MouseLeave += (s, e) => HidePointTip(); } private void InitializeLayout() @@ -283,6 +288,7 @@ namespace MesWork.Pages private void LoadCurve(DataRow row) { _points.Clear(); + HidePointTip(); string pointValues = row.Table.Columns.Contains("点位值") ? row["点位值"]?.ToString() : ""; foreach (string item in (pointValues ?? "").Split('|')) { @@ -311,6 +317,7 @@ namespace MesWork.Pages private void ClearCurve(string msg) { _points.Clear(); + HidePointTip(); _finalWeight = null; _finalStartSeq = 0; _finalEndSeq = 0; @@ -357,6 +364,7 @@ namespace MesWork.Pages if (_points.Count == 0) { + _chartPoints = new PointF[0]; DrawCenterText(g, rect, "选择一条称重记录后显示曲线"); return; } @@ -372,10 +380,10 @@ namespace MesWork.Pages DrawGrid(g, padL, padT, chartW, chartH, minVal, maxVal); - PointF[] points = BuildPointLocations(padL, padT, chartW, chartH, minVal, maxVal); - DrawHighlightWindow(g, points, padT, chartH); - DrawCurve(g, points); - DrawPoints(g, points); + _chartPoints = BuildPointLocations(padL, padT, chartW, chartH, minVal, maxVal); + DrawHighlightWindow(g, _chartPoints, padT, chartH); + DrawCurve(g, _chartPoints); + DrawPoints(g, _chartPoints); DrawFinalLine(g, padL, padT, chartW, chartH, minVal, maxVal); } @@ -470,6 +478,60 @@ namespace MesWork.Pages return _finalStartSeq > 0 && _finalEndSeq > 0 && seq >= _finalStartSeq && seq <= _finalEndSeq; } + private void pnl_Chart_MouseMove(object sender, MouseEventArgs e) + { + int index = FindNearestPointIndex(e.Location); + if (index < 0) + { + HidePointTip(); + return; + } + + int seq = index + 1; + if (seq == _lastTipSeq) return; + + _lastTipSeq = seq; + string finalText = IsInFinalWindow(seq) ? "\r\n取值依据:最终采用区间内" : ""; + string tipText = $"第 {seq} 点\r\n重量:{_points[index]:F3} kg\r\n时间:{FormatElapsedTime(seq)}{finalText}"; + tip_Point.Show(tipText, pnl_Chart, e.Location.X + 16, e.Location.Y + 16, 3000); + } + + private int FindNearestPointIndex(Point mouse) + { + if (_chartPoints.Length == 0 || _points.Count == 0) return -1; + + int nearestIndex = -1; + double nearestDistance = double.MaxValue; + for (int i = 0; i < _chartPoints.Length; i++) + { + double dx = _chartPoints[i].X - mouse.X; + double dy = _chartPoints[i].Y - mouse.Y; + double distance = dx * dx + dy * dy; + if (distance < nearestDistance) + { + nearestDistance = distance; + nearestIndex = i; + } + } + + return nearestDistance <= 144 ? nearestIndex : -1; // 鼠标离点 12px 内才显示,避免误触。 + } + + private string FormatElapsedTime(int seq) + { + int interval = _sampleIntervalMs > 0 ? _sampleIntervalMs : 200; + int totalMs = Math.Max(0, seq - 1) * interval; // 第1点按采集起点0ms估算。 + int seconds = totalMs / 1000; + int milliseconds = totalMs % 1000; + return $"{seconds}秒{milliseconds:D3}毫秒"; + } + + private void HidePointTip() + { + _lastTipSeq = 0; + tip_Point.Hide(pnl_Chart); + } + private void DrawCenterText(Graphics g, Rectangle rect, string text) { using (var font = new Font("微软雅黑", 14F))