Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Control
Public Class LEDControl
Inherits System.Windows.Forms.Control
Private mNumber As Integer = 0
#Region " Component Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
setstyle(ControlStyles.ResizeRedraw, True)
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
#End Region
Public Property Number() As Integer
Get
Return mNumber
End Get
Set(ByVal Value As Integer)
If Value >= 0 And Value < 11 Then
Dim old As Integer = mNumber
mNumber = Value
Me.Invalidate()
End If
End Set
End Property
Public Sub Inrease()
If Me.Number <> 9 Then
Me.Number += 1
Else
Me.Number = 0
End If
End Sub
Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
Dim g As Graphics = pe.Graphics
DrawNumber(g, mNumber)
End Sub
Private Sub DrawNumber(ByVal g As Graphics, ByVal num As Integer)
Dim p As New Pen(Me.ForeColor)
Select Case num
Case 0
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
'BOTTOM LEFT
g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)
Case 1
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 2
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM LEFT
g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)
Case 3
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 4
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 5
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 6
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
'BOTTOM LEFT
g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)
Case 7
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 8
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
'BOTTOM LEFT
g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)
Case 9
'TOP
g.DrawLine(p, 5, 2, Me.Width - 5, 2)
g.DrawLine(p, 4, 3, Me.Width - 4, 3)
g.DrawLine(p, 5, 4, Me.Width - 5, 4)
'MIDDLE
g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)
'BOTTOM
g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)
'TOP LEFT
g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)
'TOP RIGHT
g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)
'BOTTOM RIGHT
g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)
Case 10
Dim p2 As New Pen(Me.ForeColor, 2)
g.DrawRectangle(p2, Me.Width \ 2 - 1, Me.Height \ 4 - 2, 2, 2)
g.DrawRectangle(p2, Me.Width \ 2 - 1, 3 * Me.Height \ 4 - 2, 2, 2)
p2 = Nothing
End Select
p = Nothing
End Sub
Protected Overrides ReadOnly Property DefaultSize() As System.Drawing.Size
Get
Dim mSize As System.Drawing.Size = New System.Drawing.Size(32, 32)
Return mSize
End Get
End Property
End Class