From 3b15853821d2afc3ecb671f77d0bb525f5be6de4 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 18 Mar 2026 15:20:40 +0800 Subject: [PATCH] feat: Implement UI for drawing parameter input and note template preview. --- UI/DrawingParamsForm.cs | 28 +++++++++++++++++++++++++++- UI/ParamDrawingPanel.cs | 30 +++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/UI/DrawingParamsForm.cs b/UI/DrawingParamsForm.cs index 2d50571..7ec2320 100644 --- a/UI/DrawingParamsForm.cs +++ b/UI/DrawingParamsForm.cs @@ -758,7 +758,33 @@ namespace CadParamPluging.UI private ComboBox CreateEnumCombo(ParamDefinition def, string initialValue) { // Allow manual edit to match many "下拉列表...可手动编辑" cases. - var cb = new ComboBox { DropDownStyle = ComboBoxStyle.DropDown }; + var cb = new ComboBox { DropDownStyle = ComboBoxStyle.DropDown, DrawMode = DrawMode.OwnerDrawFixed }; + cb.DrawItem += (s, e) => + { + if (e.Index < 0) return; + e.DrawBackground(); + var text = cb.GetItemText(cb.Items[e.Index]); + TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, e.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); + e.DrawFocusRectangle(); + + if (cb.DroppedDown && (e.State & DrawItemState.Selected) == DrawItemState.Selected) + { + int lastHovered = cb.Tag is int i ? i : -1; + if (lastHovered != e.Index) + { + cb.Tag = e.Index; + var point = cb.PointToClient(Cursor.Position); + point.Y += 20; + _toolTip.Show(text, cb, point.X, point.Y); + } + } + }; + cb.DropDownClosed += (s, e) => + { + _toolTip.Hide(cb); + cb.Tag = -1; + }; + var list = (def.EnumOptions ?? new List()) .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.Trim()) diff --git a/UI/ParamDrawingPanel.cs b/UI/ParamDrawingPanel.cs index a9be87a..a723eb0 100644 --- a/UI/ParamDrawingPanel.cs +++ b/UI/ParamDrawingPanel.cs @@ -794,7 +794,35 @@ namespace CadParamPluging.UI var cb = new ComboBox { DropDownStyle = ComboBoxStyle.DropDownList, - Width = 160 + Width = 160, + DrawMode = DrawMode.OwnerDrawFixed + }; + + var toolTip = new ToolTip(); + cb.DrawItem += (s, e) => + { + if (e.Index < 0) return; + e.DrawBackground(); + var text = cb.GetItemText(cb.Items[e.Index]); + TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, e.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); + e.DrawFocusRectangle(); + + if (cb.DroppedDown && (e.State & DrawItemState.Selected) == DrawItemState.Selected) + { + int lastHovered = cb.Tag is int i ? i : -1; + if (lastHovered != e.Index) + { + cb.Tag = e.Index; + var point = cb.PointToClient(Cursor.Position); + point.Y += 20; + toolTip.Show(text, cb, point.X, point.Y); + } + } + }; + cb.DropDownClosed += (s, e) => + { + toolTip.Hide(cb); + cb.Tag = -1; }; ResetComboBoxItems(cb, items);