c# 组合框绘图项 - 刷新问题
本文关键字:刷新 新问题 绘图 组合 | 更新日期: 2023-09-27 18:31:26
我在组合框中创建了一个字体列表。我将其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();
}
在日耳中,它工作正常。鼠标滚动时出现问题。然后,某些项目看起来像随机图形,直到它们被聚焦。有人知道问题的解决方案吗?
始终调用 e.DrawBackground(),无论索引如何。 修复:
void cmbFonts_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index >= 0) {
// etc...
}
}