开发者

OwnerDrawn ListBox blank when it loses focus

开发者 https://www.devze.com 2023-03-12 17:09 出处:网络
I subscribe to the ListBox.DrawItem开发者_如何学运维 event and it draws fine when it has focus but when I navigate away it draws nothing.

I subscribe to the ListBox.DrawItem开发者_如何学运维 event and it draws fine when it has focus but when I navigate away it draws nothing.

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;
    }
}


check this

   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);

        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号