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