所有者图画控制系统 - 背景

时间:2011-09-11 06:14:49

标签: .net vb.net ownerdrawn

所有者绘制暗示我必须编写自己的绘图方法。

但是,如何在没有文本的情况下告诉系统绘制ListView项目的“系统”背景?我想手动绘制文本,而不是(蓝色)背景。

Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawListViewItemEventArgs)
    MyBase.OnDrawItem(e)

    e.DrawBackground()
    TextRenderer.DrawText(e.Graphics, "My Text", e.Item.Font, e.Bounds, e.Item.ForeColor)
End Sub

平铺视图中使用ListView,我只看到“我的文字”。

1 个答案:

答案 0 :(得分:0)

Protected Overrides Sub OnDrawItem(ByVal e As DrawListViewItemEventArgs)
    MyBase.OnDrawItem(e)

  e.DrawBackground()
  If (e.State And ListViewItemStates.Selected) <> 0 Then
    e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds)
    e.DrawFocusRectangle()
    TextRenderer.DrawText(e.Graphics, "My Text", e.Item.Font, e.Bounds, SystemColors.HighlightText, Color.Empty)
  Else
    TextRenderer.DrawText(e.Graphics, "My Text", e.Item.Font, e.Bounds, e.Item.ForeColor)
  End If
End Sub
相关问题