组合框OwnerDrawFixed - 滚动速度非常快

时间:2013-02-22 12:20:40

标签: c# winforms

我编写了以下代码来增加项目的高度。完成此操作后,在滚动组合时,与正常的组合框相比,它的移动速度非常快。我该如何解决这个问题?

我将Draw Mode设置为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; ;
    }

1 个答案:

答案 0 :(得分:0)

只有在为OwnerDrawVariable设置DrawMode时才会调用MeasureItem事件。

因此,您需要将DrawMode更改为OwnerDrawVariable,或将ComboBox的ItemHeight属性设置为值this.ItemHeight * 2

不确定滚动速度,这可能只是您的操作系统。我没有发现太大的区别 - 您没有使用stringMeasure变量,因此您可以对其进行评论。