设置该listview的owerDraw属性为true,然后 Private Sub ListView1_DrawColumnHeader(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader 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.DrawBackground() e.Graphics.FillRectangle(Brushes.SteelBlue, e.Bounds) Dim headerFont As New Font("Arial", 8, FontStyle.Bold) e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.White, e.Bounds, strFormat) End Sub
ListView的ColumnHeader是最差劲的东东,什么也扩展不了。不知2005的有没有改善
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.DrawBackground()
e.Graphics.FillRectangle(Brushes.SteelBlue, e.Bounds)
Dim headerFont As New Font("Arial", 8, FontStyle.Bold) e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.White, e.Bounds, strFormat)
End Sub