feat: Implement UI for drawing parameter input and note template preview.

This commit is contained in:
sladro 2026-03-18 15:20:40 +08:00
parent 63db980cdc
commit 3b15853821
2 changed files with 56 additions and 2 deletions

View File

@ -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<string>())
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.Trim())

View File

@ -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);