【问题标题】:c# combobox DrawItem - refreshing issuec# combobox DrawItem - 刷新问题
【发布时间】:2012-04-18 10:18:39
【问题描述】:

我在组合框中创建了一个字体列表。我将它的 DrawMode 设置为 OwnerDrawFixed,方法 DrawItem 很简单:

void cmbFonts_DrawItem(object sender, DrawItemEventArgs e)
{
    if (e.Index < 0) return;
    e.DrawBackground();

    Font newFont =
        new Font(cmbFonts.Items[e.Index].ToString(), this.DefaultFontSize);
    e.Graphics.DrawString(cmbFonts.Items[e.Index].ToString(),
                          newFont,
                          new SolidBrush(Color.Black),
                          new Rectangle(e.Bounds.Location, e.Bounds.Size));
    e.DrawFocusRectangle();
}

一般来说,它可以正常工作。问题出现在鼠标滚动上。然后一些项目看起来像随机图形,直到它们被聚焦。有人知道这个问题的解决方案吗?

【问题讨论】:

    标签: c# combobox


    【解决方案1】:

    总是调用 e.DrawBackground(),不管索引。修复:

    void cmbFonts_DrawItem(object sender, DrawItemEventArgs e)
    {
        e.DrawBackground();
        if (e.Index >= 0) {
           // etc...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      相关资源
      最近更新 更多