다음과 같은 사용자 지정 콤보 상자를 개발하여 항목 높이를 늘 렸습니다. 끝나면 스크롤바가있을 때 드롭 다운 메뉴의 끝에 빈 공간이 나타납니다. 어떻게 문제를 해결할 수 있습니까?OwnerDrawVariable Combobox DropDown 빈 공간
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();
}
}
DropDownList에 세로 스크롤 막대가있는 경우에만 문제가 발생합니다. – Maanu