首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OwnerDrawn ListBox在失去焦点时为空

OwnerDrawn ListBox在失去焦点时为空
EN

Stack Overflow用户
提问于 2011-06-13 14:04:52
回答 1查看 266关注 0票数 1

我订阅了ListBox.DrawItem事件,当它有焦点时,它绘制得很好,但当我导航离开时,它什么都不绘制。

代码语言:javascript
复制
private void lbHeader_DrawItem(object sender, DrawItemEventArgs e)
{
    e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
    e.Graphics.FillRectangle(SystemBrushes.GradientActiveCaption, e.Bounds);

    int left = e.Bounds.Left + ImageList.ImageSize.Width;
    for (int i = 0; i < Columns.Count; i++)
    {
        Rectangle textRect = Rectangle.FromLTRB(
            left, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom);
       TextRenderer.DrawText(e.Graphics, "Some Text", e.Font, textRect,
           FontColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
       left += Columns[i].Width;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2011-06-13 15:16:33

看看这个

代码语言:javascript
复制
   private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
    {
        if (e.Index > 0)
        {
            e.DrawBackground();
            e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), this.Font, Brushes.Black, e.Bounds);

        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6327138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档