PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

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

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