Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.Clear(Me.BackColor)
Dim imageWidth, imageHeight As Integer
imageWidth = (Me.Width-(LeftMargin + RightMargin + ( _
Me.m_ImageSpacing * (Me.m_ImageCount-1)))) \ Me.m_ImageCount
imageHeight = (Me.Height-(TopMargin + BottomMargin))
Dim start As New Point(Me.LeftMargin, Me.TopMargin)
For i As Integer = 0 To Me.ImageCount-1
Me.ItemAreas(i).X = start.X-Me.ImageSpacing \ 2
Me.ItemAreas(i).Y = start.Y
Me.ItemAreas(i).Width = imageWidth + Me.ImageSpacing \ 2
Me.ItemAreas(i).Height = imageHeight
If Me.ImageToDraw = UserSuppliedImage Then
DrawUserSuppliedImage(e.Graphics, _
start.X, start.Y, imageWidth, imageHeight, i)
Else
DrawStandardImage(e.Graphics, Me.ImageToDraw, _
start.X, start.Y, imageWidth, imageHeight, i)
End If
start.X += imageWidth + Me.ImageSpacing
Next
MyBase.OnPaint(e)
End Sub
Protected Overridable Sub DrawUserSuppliedImage( _
ByVal g As Graphics, _
ByVal x As Integer, ByVal y As Integer, _
ByVal w As Integer, ByVal h As Integer, _
ByVal currentPos As Integer)
Dim img As Image
If m_hovering And m_hoverItem > currentPos Then
img = Me.HoverImage
ElseIf Not m_hovering And m_selectedItem > currentPos Then
img = Me.FilledImage
Else
img = Me.EmptyImage
End If
If Not img Is Nothing Then
g.DrawImage(img, x, y, w, h)
Else
Me.DrawStandardImage(g, Me.Circle, x, y, w, h, currentPos)
End If
End Sub
Protected Overridable Sub DrawStandardImage( _
ByVal g As Graphics, ByVal ImageType As Integer, _
ByVal x As Integer, ByVal y As Integer, _
ByVal w As Integer, ByVal h As Integer, _
ByVal currentPos As Integer)
Dim fillBrush As Brush
Dim outlinePen As Pen = New Pen(Me.OutlineColor, 1)
If m_hovering And m_hoverItem > currentPos Then
fillBrush = New SolidBrush(Me.HoverColor)
ElseIf Not m_hovering And m_selectedItem > currentPos Then
fillBrush = New SolidBrush(Me.SelectedColor)
Else
fillBrush = New SolidBrush(Me.EmptyColor)
End If
Select Case ImageType
Case Me.Square
g.FillRectangle(fillBrush, x, y, w, h)
g.DrawRectangle(outlinePen, x, y, w, h)
Case Me.Circle
g.FillEllipse(fillBrush, x, y, w, h)
g.DrawEllipse(outlinePen, x, y, w, h)
End Select
End Sub |