/Source Code/PowerSong/Custom Controls/SongsListBox.vb
Visual Basic | 105 lines | 78 code | 22 blank | 5 comment | 0 complexity | 53435ff705645bc812ad40a26be7e20a MD5 | raw file
- Imports PowerSong.SongDatabase
-
- Public Class SongsListBox
-
- Public Function ItemCount() As Integer
- Return FBaseList.Items.Count
- End Function
-
- Public Shadows Function Items(ByVal index As Integer) As SongsListItem
- Return FBaseList.Items(index)
- End Function
-
- Private FBaseList As ListBox = Nothing
- Private FBoldFont As Font = Nothing
- Private FSmallFont As Font = Nothing
-
- Public Sub New()
- InitializeComponent()
- ItemHeight = SongsListItem.ICON_HEIGHT
- IntegralHeight = False
- DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
- FBaseList = Me
- FBoldFont = New Font(Me.Font, FontStyle.Bold)
- FSmallFont = New Font(Me.Font.FontFamily, CInt(CDbl(Me.Font.Size * 0.8)), FontStyle.Italic, GraphicsUnit.Point)
- End Sub
-
- Public Sub AddItem(ByVal item As SongsListItem)
- FBaseList.Items.Add(item)
- AddHandler item.NeedsRepainting, AddressOf Invalidate
- Invalidate()
- End Sub
-
- Public Sub RemoveItem(ByVal item As SongsListItem)
- FBaseList.Items.Remove(item)
- Invalidate()
- End Sub
-
- Public Sub Clear()
- FBaseList.Items.Clear()
- Invalidate()
- End Sub
-
- Private FActiveItem As SongsListItem = Nothing
-
- Public Property ActiveItem() As SongsListItem
- Get
- Return FActiveItem
- End Get
- Set(ByVal value As SongsListItem)
- FActiveItem = value
- Invalidate()
- End Set
- End Property
-
- Public Sub MoveUp()
- If SelectedIndex <= 0 Then Exit Sub
- Dim UpItem As Object = FBaseList.Items(SelectedIndex - 1)
- FBaseList.Items(SelectedIndex - 1) = FBaseList.Items(SelectedIndex)
- FBaseList.Items(SelectedIndex) = UpItem
- SelectedIndex -= 1
- End Sub
-
- Public Sub MoveDown()
- If SelectedIndex >= ItemCount() - 1 Then Exit Sub
- Dim DownItem As Object = FBaseList.Items(SelectedIndex + 1)
- FBaseList.Items(SelectedIndex + 1) = FBaseList.Items(SelectedIndex)
- FBaseList.Items(SelectedIndex) = DownItem
- SelectedIndex += 1
- End Sub
-
- Private Sub SongsListBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyClass.DrawItem
-
- e.DrawBackground()
- e.DrawFocusRectangle()
-
- ' Get the item
- If e.Index = -1 OrElse e.Index >= FBaseList.Items.Count Then Exit Sub
- Dim Item As SongsListItem = DirectCast(FBaseList.Items(e.Index), SongsListItem)
-
- ' Draw active item if it exists
- If FActiveItem Is Item Then e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
-
- ' Draw the icon
- Dim Left As Integer = e.Bounds.Left + 1
- e.Graphics.DrawImage(Item.Icon, Left, e.Bounds.Top + 2)
- Left += Item.Icon.Width + 2
-
- ' Determine style text
- Dim StyleText As String = "Default Style"
- If Item.Style IsNot Nothing Then StyleText = "Style: " + Item.Style.Name
-
- ' Draw the text for the item
- If FActiveItem Is Item Then
- e.Graphics.DrawString(Item.Item.Title, FBoldFont, Brushes.White, Left, e.Bounds.Top)
- e.Graphics.DrawString(StyleText, Font, Brushes.White, Left, e.Bounds.Top + 18)
- Else
- e.Graphics.DrawString(Item.Item.Title, FBoldFont, SystemBrushes.ControlText, Left, e.Bounds.Top)
- e.Graphics.DrawString(StyleText, Font, SystemBrushes.GrayText, Left, e.Bounds.Top + 18)
- End If
-
- e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
-
- End Sub
-
- End Class