/Source Code/PowerSong/Custom Controls/VersesListBox.vb

# · Visual Basic · 55 lines · 41 code · 12 blank · 2 comment · 0 complexity · 7fdc802200929e594cf578979f5d2375 MD5 · raw file

  1. Imports PowerSong.SongDatabase
  2. Public Class VersesListBox
  3. Public Sub New()
  4. InitializeComponent()
  5. IntegralHeight = False
  6. DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
  7. End Sub
  8. Private FActiveIndex As Integer = -1
  9. Public Property ActiveIndex() As Integer
  10. Get
  11. Return FActiveIndex
  12. End Get
  13. Set(ByVal value As Integer)
  14. FActiveIndex = value
  15. Invalidate()
  16. End Set
  17. End Property
  18. Private Sub SongsListBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyClass.DrawItem
  19. e.DrawBackground()
  20. e.DrawFocusRectangle()
  21. ' Get the item
  22. If e.Index = -1 OrElse e.Index >= Items.Count Then Exit Sub
  23. ' Draw active item if it exists
  24. If FActiveIndex = e.Index Then
  25. e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
  26. e.Graphics.DrawString(Items(e.Index), New Font(Me.Font, FontStyle.Bold), SystemBrushes.Window, e.Bounds)
  27. Else
  28. If e.State = DrawItemState.Focus Then
  29. e.Graphics.DrawString(Items(e.Index), Me.Font, SystemBrushes.MenuText, e.Bounds)
  30. Else
  31. e.Graphics.DrawString(Items(e.Index), Me.Font, SystemBrushes.WindowText, e.Bounds)
  32. End If
  33. End If
  34. e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
  35. End Sub
  36. Private Sub VersesListBox_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Me.MeasureItem
  37. If e.Index > -1 AndAlso e.Index < Items.Count Then
  38. Dim Size As New SizeF(Me.ClientRectangle.Width, 320)
  39. Dim Text As String = Items(e.Index)
  40. e.ItemHeight = CInt(e.Graphics.MeasureString(Text, Me.Font, Size).Height)
  41. End If
  42. End Sub
  43. End Class