如何设置listview对象的标题列的垂直对齐以适合单元格边框内的文本(无法自动设置标题表单的高度)
ListView1.Columns.Add(items.InnerText, 90, HorizontalAlignment.Center)
将“strformat”添加到drawcolumnheader正在进行水平对齐,但不适用于垂直对齐
Private Sub ListView3_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView3.DrawColumnHeader
Dim strFormat As New StringFormat()
If e.Header.TextAlign = HorizontalAlignment.Center Then
strFormat.LineAlignment = StringAlignment.Center
strFormat.Alignment = StringAlignment.Center
ElseIf e.Header.TextAlign = HorizontalAlignment.Right Then
strFormat.LineAlignment = 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
根据@Jimi的建议,处理标题文本对齐的最佳方法是使用Datagridview而不是Listview。 Datagridview具有许多功能,包括标题文本,行和列调整。