C# 列表项下拉窗口宽度自适应
/// <summary> /// 列表项下拉窗口宽度自适应 /// </summary> /// <param name="comboBox"></param> private void ComboBoxAutoDropDownListWidth(ComboBox comboBox) { int maxWidth = 0, temp = 0; foreach (var obj in comboBox.Items) { temp = TextRenderer.MeasureText(comboBox.GetItemText(obj), comboBox.Font).Width; if (temp > maxWidth) { maxWidth = temp; } } comboBox.DropDownWidth= maxWidth + SystemInformation.VerticalScrollBarWidth+2; }
https://www.itranslater.com/qa/details/2583418447979873280