Imports System.Drawing
Imports System.Windows.Forms
Public Class WrapedListBox
Inherits System.Windows.Forms.ListBox
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
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)
e.DrawFocusRectangle()
MyBase.OnDrawItem(e)
End Sub
End Class
SW1wb3J0cyBTeXN0ZW0uRHJhd2luZwoKSW1wb3J0cyBTeXN0ZW0uV2luZG93cy5Gb3JtcwoKCgpQdWJsaWMgQ2xhc3MgV3JhcGVkTGlzdEJveAoKICAgIEluaGVyaXRzIFN5c3RlbS5XaW5kb3dzLkZvcm1zLkxpc3RCb3gKCgoKICAgIFByb3RlY3RlZCBPdmVycmlkZXMgU3ViIE9uTWVhc3VyZUl0ZW0oQnlWYWwgZSBBcyBTeXN0ZW0uV2luZG93cy5Gb3Jtcy5NZWFzdXJlSXRlbUV2ZW50QXJncykKCgoKICAgICAgICBJZiBEZXNpZ25Nb2RlIFRoZW4KCiAgICAgICAgICAgIE15QmFzZS5Pbk1lYXN1cmVJdGVtKGUpCgogICAgICAgICAgICBFeGl0IFN1YgoKICAgICAgICBFbmQgSWYKCgoKICAgICAgICBEaW0gcHJvcG9zZWRTaXplIEFzIFNpemUgPSBOZXcgU2l6ZShNZS5DbGllbn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