我编写了以下代码来增加项目的高度。完成此操作后,在滚动组合时,与普通组合框相比,它以非常高的速度移动。我该如何解决这个问题?
我已将绘图模式设置为 DrawMode.OwnerDrawFixed;
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
System.Diagnostics.Debug.WriteLine(e.State);
if (e.Index < 0)
{
return;
}
SizeF stringMeasure = e.Graphics.MeasureString(this.Items[e.Index].ToString(), e.Font);
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();
}
private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = this.ItemHeight * 2; ;
}