Imports System.Drawing
Imports System.Windows.Forms
Public Class WrapedListBox
Inherits System.Windows.Forms.ListBox
Public Sub New()
Me.ScrollAlwaysVisible = True
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
End Sub
Protected Overrides Sub OnClientSizeChanged(e As EventArgs)
MyBase.OnClientSizeChanged(e)
Me.Refresh()
End Sub
Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
If DesignMode Then
MyBase.OnMeasureItem(e)
Exit Sub
End If
Dim proposedSize As Size = New Size(Me.ClientSize.Width, Integer.MaxValue)
'Dim flags As TextFormatFlags = TextFormatFlags.WordBreak
'Dim returnValue As Size = TextRenderer.MeasureText(e.Graphics, Me.Items(e.Index).ToString, Me.Font, proposedSize, flags)
'e.ItemWidth = returnValue.Width
'e.ItemHeight = returnValue.Height
Using sf = New System.Drawing.StringFormat()
Dim sizeF As SizeF = e.Graphics.MeasureString(Me.Items(e.Index).ToString(), Me.Font, proposedSize, sf)
e.ItemWidth = Convert.ToInt32(sizeF.Width + 0.9)
e.ItemHeight = Convert.ToInt32(sizeF.Height + 4.9)
End Using
MyBase.OnMeasureItem(e)
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
If DesignMode Then
MyBase.OnDrawItem(e)
Exit Sub
End If
e.DrawBackground()
'Dim brush = New SolidBrush(e.ForeColor)
'e.Graphics.DrawString(Me.Items(e.Index).ToString, e.Font, brush, e.Bounds, StringFormat.GenericDefault)
Using brush = New SolidBrush(e.ForeColor)
Using sf = New System.Drawing.StringFormat()
Dim rect As Rectangle = e.Bounds
e.Graphics.DrawString(Me.Items(e.Index).ToString, e.Font, brush, rect, sf)
End Using
End Using
MyBase.OnDrawItem(e)
End Sub
End Class
SW1wb3J0cyBTeXN0ZW0uRHJhd2luZwpJbXBvcnRzIFN5c3RlbS5XaW5kb3dzLkZvcm1zCgpQdWJsaWMgQ2xhc3MgV3JhcGVkTGlzdEJveAoKICAg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