开发者

Owner drawing control system-background

开发者 https://www.devze.com 2023-04-03 20:55 出处:网络
Owner draw implies that I have to code my own drawing methods. However, how can I tell the system to draw the \"system\" background of my ListView item, without the text? I would like to manually dra

Owner draw implies that I have to code my own drawing methods.

However, how can I tell the system to draw the "system" background of my ListView item, without the text? I would like to manually draw the text, not the (blue) background.

Protecte开发者_如何学编程d 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

Using ListView in Tile view, I just see "My Text".


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
0

精彩评论

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

关注公众号