fork download
  1. Imports System.Windows.Forms
  2. Imports System.Drawing
  3.  
  4. Public Class ListBoxEx : Inherits ListBox
  5.  
  6. Public Sub New()
  7. MyBase.New()
  8. DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
  9. AddHandler Application.Idle, AddressOf Application_Idle
  10. End Sub
  11.  
  12. Private ReadOnly Property ItemTextFormat() As StringFormat
  13. Get
  14. Static sf As StringFormat
  15. If sf Is Nothing Then
  16. sf = New StringFormat(StringFormatFlags.LineLimit)
  17. sf.Trimming = StringTrimming.Character
  18. End If
  19. Return sf
  20. End Get
  21. End Property
  22.  
  23. Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
  24. If Items.Count < 1 Then Return
  25.  
  26. Dim item = Items(e.Index)
  27. If item Is Nothing Then item = ""
  28. e.ItemHeight = CInt(e.Graphics.MeasureString(item.ToString, Font, ClientSize.Width, ItemTextFormat).Height)
  29. End Sub
  30.  
  31. Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
  32. If Items.Count < 1 Then Return
  33.  
  34. e.DrawBackground()
  35. Using br As New SolidBrush(e.ForeColor)
  36. Dim item = Items(e.Index)
  37. If item IsNot Nothing Then
  38. e.Graphics.DrawString(item.ToString, Font, br, e.Bounds, ItemTextFormat)
  39. End If
  40. End Using
  41. e.DrawFocusRectangle()
  42.  
  43. End Sub
  44.  
  45. Protected Overrides Sub OnClientSizeChanged(ByVal e As System.EventArgs)
  46. MyBase.OnClientSizeChanged(e)
  47. remeasuresItems = True
  48. End Sub
  49.  
  50. Private remeasuresItems As Boolean = False
  51.  
  52. Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
  53. If Not remeasuresItems Then Return
  54. RemeasureItems()
  55. remeasuresItems = False
  56. End Sub
  57.  
  58. Private Sub RemeasureItems()
  59. DrawMode = Windows.Forms.DrawMode.Normal
  60. DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
  61. End Sub
  62.  
  63. End Class
  64.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Visual Basic.Net Compiler version 0.0.0.5914 (Mono 2.4.2 - r)
Copyright (C) 2004-2008 Rolf Bjarne Kvinge. All rights reserved.


A warning message should have been shown: 'Variable type should be specified.'
A warning message should have been shown: 'Variable type should be specified.'
/home/4oW9UI/prog.vb (38,28) : Error VBNC99999: No non-narrowing (except object): /home/4oW9UI/prog.vb (38,28)
There were 1 errors and 0 warnings.
Compilation took 00:00:01.1264390
stdout
Standard output is empty