From 59f71a433ab0b3db53b4cb71d0a66ee3d1975256 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 14 Jan 2026 13:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI/DrawingParamsForm.cs | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/UI/DrawingParamsForm.cs b/UI/DrawingParamsForm.cs index 9dabdf7..408fe4c 100644 --- a/UI/DrawingParamsForm.cs +++ b/UI/DrawingParamsForm.cs @@ -702,7 +702,12 @@ namespace CadParamPluging.UI { // Allow manual edit to match many "下拉列表...可手动编辑" cases. var cb = new ComboBox { DropDownStyle = ComboBoxStyle.DropDown }; - var arr = (def.EnumOptions ?? new List()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray(); + var list = (def.EnumOptions ?? new List()) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Select(x => x.Trim()) + .ToList(); + + var arr = list.ToArray(); if (arr.Length > 0) { cb.Items.AddRange(arr); @@ -716,6 +721,41 @@ namespace CadParamPluging.UI { cb.Text = initialValue; } + + // Auto-match functionality: filter items as user types (Contains logic) + cb.TextUpdate += (s, e) => + { + var text = cb.Text; + var selectionStart = cb.SelectionStart; + var selectionLength = cb.SelectionLength; + + // Empty text -> Show all? Or keep filtered? + // Usually empty -> Show all. + var matches = string.IsNullOrEmpty(text) + ? arr + : list.Where(x => x.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0).ToArray(); + + cb.BeginUpdate(); + cb.Items.Clear(); + if (matches.Length > 0) + { + cb.Items.AddRange(matches); + } + cb.EndUpdate(); + + // Restoring SelectionStart is critical because updating Items resets it + cb.SelectionStart = selectionStart; + cb.SelectionLength = selectionLength; + + if (!cb.DroppedDown) + { + cb.DroppedDown = true; + } + + // Keep the mouse cursor visible/normal + Cursor.Current = Cursors.Default; + }; + return cb; }