PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Visual Basic | 105 lines | 78 code | 22 blank | 5 comment | 0 complexity | 53435ff705645bc812ad40a26be7e20a MD5 | raw file
  1. Imports PowerSong.SongDatabase
  2. Public Class SongsListBox
  3. Public Function ItemCount() As Integer
  4. Return FBaseList.Items.Count
  5. End Function
  6. Public Shadows Function Items(ByVal index As Integer) As SongsListItem
  7. Return FBaseList.Items(index)
  8. End Function
  9. Private FBaseList As ListBox = Nothing
  10. Private FBoldFont As Font = Nothing
  11. Private FSmallFont As Font = Nothing
  12. Public Sub New()
  13. InitializeComponent()
  14. ItemHeight = SongsListItem.ICON_HEIGHT
  15. IntegralHeight = False
  16. DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  17. FBaseList = Me
  18. FBoldFont = New Font(Me.Font, FontStyle.Bold)
  19. FSmallFont = New Font(Me.Font.FontFamily, CInt(CDbl(Me.Font.Size * 0.8)), FontStyle.Italic, GraphicsUnit.Point)
  20. End Sub
  21. Public Sub AddItem(ByVal item As SongsListItem)
  22. FBaseList.Items.Add(item)
  23. AddHandler item.NeedsRepainting, AddressOf Invalidate
  24. Invalidate()
  25. End Sub
  26. Public Sub RemoveItem(ByVal item As SongsListItem)
  27. FBaseList.Items.Remove(item)
  28. Invalidate()
  29. End Sub
  30. Public Sub Clear()
  31. FBaseList.Items.Clear()
  32. Invalidate()
  33. End Sub
  34. Private FActiveItem As SongsListItem = Nothing
  35. Public Property ActiveItem() As SongsListItem
  36. Get
  37. Return FActiveItem
  38. End Get
  39. Set(ByVal value As SongsListItem)
  40. FActiveItem = value
  41. Invalidate()
  42. End Set
  43. End Property
  44. Public Sub MoveUp()
  45. If SelectedIndex <= 0 Then Exit Sub
  46. Dim UpItem As Object = FBaseList.Items(SelectedIndex - 1)
  47. FBaseList.Items(SelectedIndex - 1) = FBaseList.Items(SelectedIndex)
  48. FBaseList.Items(SelectedIndex) = UpItem
  49. SelectedIndex -= 1
  50. End Sub
  51. Public Sub MoveDown()
  52. If SelectedIndex >= ItemCount() - 1 Then Exit Sub
  53. Dim DownItem As Object = FBaseList.Items(SelectedIndex + 1)
  54. FBaseList.Items(SelectedIndex + 1) = FBaseList.Items(SelectedIndex)
  55. FBaseList.Items(SelectedIndex) = DownItem
  56. SelectedIndex += 1
  57. End Sub
  58. Private Sub SongsListBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyClass.DrawItem
  59. e.DrawBackground()
  60. e.DrawFocusRectangle()
  61. ' Get the item
  62. If e.Index = -1 OrElse e.Index >= FBaseList.Items.Count Then Exit Sub
  63. Dim Item As SongsListItem = DirectCast(FBaseList.Items(e.Index), SongsListItem)
  64. ' Draw active item if it exists
  65. If FActiveItem Is Item Then e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
  66. ' Draw the icon
  67. Dim Left As Integer = e.Bounds.Left + 1
  68. e.Graphics.DrawImage(Item.Icon, Left, e.Bounds.Top + 2)
  69. Left += Item.Icon.Width + 2
  70. ' Determine style text
  71. Dim StyleText As String = "Default Style"
  72. If Item.Style IsNot Nothing Then StyleText = "Style: " + Item.Style.Name
  73. ' Draw the text for the item
  74. If FActiveItem Is Item Then
  75. e.Graphics.DrawString(Item.Item.Title, FBoldFont, Brushes.White, Left, e.Bounds.Top)
  76. e.Graphics.DrawString(StyleText, Font, Brushes.White, Left, e.Bounds.Top + 18)
  77. Else
  78. e.Graphics.DrawString(Item.Item.Title, FBoldFont, SystemBrushes.ControlText, Left, e.Bounds.Top)
  79. e.Graphics.DrawString(StyleText, Font, SystemBrushes.GrayText, Left, e.Bounds.Top + 18)
  80. End If
  81. e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
  82. End Sub
  83. End Class