当试图自定义绘制我的彩色标题和列表查看项时,我得到的是锯齿状的文本(而不是反别名),这看起来很糟糕。我看到了下面的代码片段来呈现文本并更好地显示--这是可行的。然而,我想不出如何把我的文字放在专栏的中心。目前,将我的标志设置为HorizontalCentre实际上将文本集中在整个listview控件中。
Private Sub lsvOverdueCalls_DrawItem(sender As Object, e As DrawListViewItemEventArgs) Handles lsvOverdueCalls.DrawItem
If e.Item.Selected AndAlso e.Item.ListView.Focused Then
e.Item.BackColor = SystemColors.Highlight
e.Item.ForeColor = e.Item.ListView.BackColor
ElseIf e.Item.Selected AndAlso Not e.Item.ListView.Focused Then
e.Item.BackColor = SystemColors.Control
e.Item.ForeColor = e.Item.ListView.ForeColor
Else
e.Item.BackColor = e.Item.ListView.BackColor
e.Item.ForeColor = e.Item.ListView.ForeColor
End If
e.DrawBackground()
' Draw the header text.
Dim rec As New Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Height - 4)
Dim flags As TextFormatFlags = TextFormatFlags.HorizontalCenter Or TextFormatFlags.EndEllipsis Or TextFormatFlags.ExpandTabs Or TextFormatFlags.SingleLine
TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Item.ListView.Font, rec, e.Item.ForeColor, flags)
End Sub我的结果是:

我需要呼叫号码(26155)坐在呼叫ID列的中心。
发布于 2014-02-12 03:22:41
e.Bounds是整个宽度。若要获取列的宽度,请尝试引用ListView列的宽度属性。
如果您给列键,请按键引用它们:
listView1.Columns("callID").Width或索引:
listView1.Columns(0).Width然后,您的绘图矩形将如下所示:
Dim colWidth As Integer = listView1.Columns("callID").Width
Dim rec As New Rectangle(e.Bounds.X, e.Bounds.Y, _
colWidth, e.Bounds.Height)https://stackoverflow.com/questions/21715958
复制相似问题