I have a custom ListBox in which I'm inheriting the Framework's ListBox and am allowing the items to be displayed on more than 1 line, so I'm using the OnMeasureItem internally, which is working fine except if it's using a larger font, I want the item's height to take font size into consideration too. Here's my code:
I was thinking that e.ItemHeight would be the height of a single line of text (like normal) with the font's height already taken into consideration and I simply need to multiply it by the current item's number of lines since that's all I'm really doing, but that doesn't seem to be the case and I thought I would ask while researching. Any ideas?
VB.NET:
Public Class MultilineListbox
Inherits System.Windows.Forms.ListBox
Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
MyBase.OnMeasureItem(e)
If Me.Items.Count > 0I Then
Dim lines() As String = Me.GetItemText(Me.Items(e.Index)).Split(CChar(Environment.NewLine))
e.ItemHeight *= lines.Length
End If
End Sub
End Class