/Source Code/PowerSong/Custom Controls/VersesListBox.vb
Visual Basic | 55 lines | 41 code | 12 blank | 2 comment | 0 complexity | 7fdc802200929e594cf578979f5d2375 MD5 | raw file
- Imports PowerSong.SongDatabase
-
- Public Class VersesListBox
-
- Public Sub New()
- InitializeComponent()
- IntegralHeight = False
- DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
- End Sub
-
- Private FActiveIndex As Integer = -1
-
- Public Property ActiveIndex() As Integer
- Get
- Return FActiveIndex
- End Get
- Set(ByVal value As Integer)
- FActiveIndex = value
- Invalidate()
- End Set
- End Property
-
- 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 >= Items.Count Then Exit Sub
-
- ' Draw active item if it exists
- If FActiveIndex = e.Index Then
- e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
- e.Graphics.DrawString(Items(e.Index), New Font(Me.Font, FontStyle.Bold), SystemBrushes.Window, e.Bounds)
- Else
- If e.State = DrawItemState.Focus Then
- e.Graphics.DrawString(Items(e.Index), Me.Font, SystemBrushes.MenuText, e.Bounds)
- Else
- e.Graphics.DrawString(Items(e.Index), Me.Font, SystemBrushes.WindowText, e.Bounds)
- End If
- End If
-
- e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
-
- End Sub
-
- Private Sub VersesListBox_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Me.MeasureItem
- If e.Index > -1 AndAlso e.Index < Items.Count Then
- Dim Size As New SizeF(Me.ClientRectangle.Width, 320)
- Dim Text As String = Items(e.Index)
- e.ItemHeight = CInt(e.Graphics.MeasureString(Text, Me.Font, Size).Height)
- End If
- End Sub
-
- End Class