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; }