OwnerDrawn ListBox 失去焦点时为空白
我订阅了 ListBox.DrawItem
事件,当它具有焦点时它绘制得很好,但当我离开时它什么也绘制不了。
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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查这个
check this