.net 绘制列表视图列标题分隔符?

.net 绘制列表视图列标题分隔符?,.net,vb.net,winforms,listview,user-controls,.net,Vb.net,Winforms,Listview,User Controls,我试图在details模式下绘制Listview的列标题 此代码: Public Sub Me_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) _ Handles Me.DrawColumnHeader e.DrawDefault = False ' Set ownerdraw. e.Graphics.FillRectangle(Brushes.Ste

我试图在
details
模式下绘制Listview的列标题

此代码:

Public Sub Me_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) _
Handles Me.DrawColumnHeader

    e.DrawDefault = False ' Set ownerdraw.

    e.Graphics.FillRectangle(Brushes.SteelBlue, e.Bounds)
    e.DrawText()

End Sub
产生以下结果:

但我想像windows那样绘制垂直分隔线:

更新:

我找到了画它们的方法:

e.Graphics.DrawLine(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.Left, e.Bounds.Right)
但似乎没有相同的锚

另外请注意,我的标题文本离分隔线太近,并且高于原始windows listview:

比较它们:

拥有:

原件:

这是我用来绘制文本的代码:

    e.DrawDefault = False ' Set ownerdraw.

    Dim strFormat As New StringFormat()

    If e.Header.TextAlign = HorizontalAlignment.Center Then
        strFormat.Alignment = StringAlignment.Center
    ElseIf e.Header.TextAlign = HorizontalAlignment.Right Then
        strFormat.Alignment = StringAlignment.Far
    End If

    e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(120, 147, 73)), e.Bounds)
    e.Graphics.DrawString(e.Header.Text, e.Font, Brushes.Black, e.Bounds, strFormat)
    e.Graphics.DrawLine(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.Left, e.Bounds.Right)
以下是
DrawListViewColumnHeaderEventArgs
的.DrawBackground和.DrawText方法在不使用视觉样式的情况下呈现的方式:

e.DrawDefault = False  ' Set ownerdraw.


'BACKGROUND

Using brush As Brush = New SolidBrush(e.BackColor)
    e.Graphics.FillRectangle(brush, e.Bounds)
End Using

Dim bounds As Rectangle = e.Bounds

bounds.Width -= 1
bounds.Height -= 1

e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, bounds)

bounds.Width -= 1
bounds.Height -= 1

e.Graphics.DrawLine(SystemPens.ControlLightLight, bounds.X, bounds.Y, bounds.Right, bounds.Y)
e.Graphics.DrawLine(SystemPens.ControlLightLight, bounds.X, bounds.Y, bounds.X, bounds.Bottom)
e.Graphics.DrawLine(SystemPens.ControlDark, (bounds.X + 1), bounds.Bottom, bounds.Right, bounds.Bottom)
e.Graphics.DrawLine(SystemPens.ControlDark, bounds.Right, (bounds.Y + 1), bounds.Right, bounds.Bottom)

'TEXT

Dim textAlign As HorizontalAlignment = e.Header.TextAlign
Dim flags As TextFormatFlags = If((textAlign = HorizontalAlignment.Left), TextFormatFlags.GlyphOverhangPadding, If((textAlign = HorizontalAlignment.Center), TextFormatFlags.HorizontalCenter, TextFormatFlags.Right))

'(I added this line)
flags = (flags Or TextFormatFlags.VerticalCenter)

Dim text As String = e.Header.Text
Dim width As Integer = TextRenderer.MeasureText(" ", e.Font).Width
bounds = Rectangle.Inflate(e.Bounds, -width, 0)
TextRenderer.DrawText(e.Graphics, [text], e.Font, bounds, e.ForeColor, flags)

这是一个灵活的解决方案,可以自定义所有内容,非常感谢