说明:C#中ComboBox控件在项过长时,会显示不全
例如:
运行之后,字体显示不完整
我们需要重写ComboBox控件
class CustomCombox : ComboBox {
protected override void OnDropDown(EventArgs e) {
base.OnDropDown(e);
AdjustComboBoxDropDownListWidth();
}
private void AdjustComboBoxDropDownListWidth() {
int vertScrollBarWidth = (this.Items.Count > this.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
int maxWidth = this.DropDownWidth;
foreach (var layouts in this.Items) {
int measureTextWidth = TextRenderer.MeasureText(layouts.ToString(), this.Font).Width;
maxWidth = maxWidth &