fork download
  1. Imports System.Drawing
  2.  
  3. Imports System.Windows.Forms
  4.  
  5.  
  6.  
  7. Public Class WrapedListBox
  8.  
  9. Inherits System.Windows.Forms.ListBox
  10.  
  11.  
  12.  
  13. Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
  14.  
  15.  
  16.  
  17. If DesignMode Then
  18.  
  19. MyBase.OnMeasureItem(e)
  20.  
  21. Exit Sub
  22.  
  23. End If
  24.  
  25.  
  26.  
  27. Dim proposedSize As Size = New Size(Me.ClientSize.Width, Integer.MaxValue)
  28.  
  29. Dim flags As TextFormatFlags = TextFormatFlags.WordBreak
  30.  
  31. Dim returnValue As Size = TextRenderer.MeasureText(e.Graphics, Me.Items(e.Index).ToString, Me.Font, proposedSize, flags)
  32.  
  33.  
  34.  
  35. e.ItemWidth = returnValue.Width
  36.  
  37. e.ItemHeight = returnValue.Height
  38.  
  39.  
  40.  
  41. MyBase.OnMeasureItem(e)
  42.  
  43.  
  44.  
  45. End Sub
  46.  
  47.  
  48.  
  49. Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
  50.  
  51.  
  52.  
  53. If DesignMode Then
  54.  
  55. MyBase.OnDrawItem(e)
  56.  
  57. Exit Sub
  58.  
  59. End If
  60.  
  61.  
  62.  
  63. e.DrawBackground()
  64.  
  65.  
  66.  
  67. Dim brush = New SolidBrush(e.ForeColor)
  68.  
  69. e.Graphics.DrawString(Me.Items(e.Index).ToString, e.Font, brush, e.Bounds, StringFormat.GenericDefault)
  70.  
  71.  
  72.  
  73. e.DrawFocusRectangle()
  74.  
  75.  
  76.  
  77. MyBase.OnDrawItem(e)
  78.  
  79.  
  80.  
  81. End Sub
  82.  
  83.  
  84.  
  85. End Class
  86.  
  87.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty