我开发了以下自定义组合框来增加项目的高度。完成后,当有滚动条时,下拉菜单的末尾会出现一个空白区域。 我该如何纠正这个问题?
class MyComboBoxXX : ComboBox
{
public MyComboBoxXX():base()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
this.DropDownStyle = ComboBoxStyle.DropDownList;
this.MaxDropDownItems = 5;
this.IntegralHeight = false;
}
protected override void OnMeasureItem(MeasureItemEventArgs e)
{
e.ItemHeight = 40;
this.DropDownHeight = 40 * 5;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
var index = e.Index;
if (index < 0 || index >= Items.Count) return;
using (var brush = new SolidBrush(e.ForeColor))
{
Rectangle rec = new Rectangle(e.Bounds.Left, e.Bounds.Top + ((e.Bounds.Height - ItemHeight) / 2), e.Bounds.Width, ItemHeight);
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(this.ForeColor), rec);
}
e.DrawFocusRectangle();
}
}