修改ListBox行高

不打扰是莪最后的温柔 提交于 2020-03-27 05:10:42

''修改ItemHeight无效

    Private Sub ListBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ListBox1.DrawItem
        e.DrawBackground()
        e.DrawFocusRectangle()
        '' 让文字位于Item的中间
        '' Dim difH as single = (e.Bounds.Height - e.Font.Height) / 2
        '' dim rf as RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y + difH, e.Bounds.Width, e.Font.Height)
        '' e.Graphics.DrawString(listBox1.Items(e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), rf)
        e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), e.Font, New SolidBrush(Color.Black), e.Bounds)
    End Sub

    Private Sub ListBox1_MeasureItem(sender As Object, e As MeasureItemEventArgs) Handles ListBox1.MeasureItem
        e.ItemHeight = 18
        '' If (e.Index = 2) ''只设置第三项的高度
        ''  e.ItemHeight = 50
        '' End If
    End Sub

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!