|
Imports System.Drawing.Design
Imports System.Windows.Forms.Design
Imports System.Text.RegularExpressions
Imports System.Globalization
Imports System.Threading
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Control
Public Class LEDClock
Inherits System.Windows.Forms.UserControl
Private mTime As String
Private otter As New ThreadStart(AddressOf MyThreadProc)
Private oThread As New Thread(otter)
Private flag As Boolean = False
Private stoped As Boolean = False
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
MyInitializeComponent()
End Sub
Private Sub MyInitializeComponent()
Dim dtfi As DateTimeFormatInfo
dtfi = DateTimeFormatInfo.InvariantInfo
Dim dt As DateTime = DateTime.Now
Me.Time = dt.ToString("T", dtfi)
oThread.Start()
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
flag = True
oThread.Abort()
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents LedControl1 As WinControls.LEDControl
Friend WithEvents LedControl2 As WinControls.LEDControl
Friend WithEvents LedControl3 As WinControls.LEDControl
Friend WithEvents LedControl4 As WinControls.LEDControl
Friend WithEvents LedControl5 As WinControls.LEDControl
Friend WithEvents LedControl6 As WinControls.LEDControl
Friend WithEvents LedControl7 As WinControls.LEDControl
Friend WithEvents LedControl8 As WinControls.LEDControl
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.LedControl1 = New WinControls.LEDControl()
Me.LedControl2 = New WinControls.LEDControl()
Me.LedControl3 = New WinControls.LEDControl()
Me.LedControl4 = New WinControls.LEDControl()
Me.LedControl5 = New WinControls.LEDControl()
Me.LedControl6 = New WinControls.LEDControl()
Me.LedControl7 = New WinControls.LEDControl()
Me.LedControl8 = New WinControls.LEDControl()
Me.SuspendLayout()
'
'LedControl1
'
Me.LedControl1.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl1.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl1.Name = "LedControl1"
Me.LedControl1.Number = 0
Me.LedControl1.TabIndex = 0
Me.LedControl1.TabStop = False
Me.LedControl1.Text = "LedControl1"
'
'LedControl2
'
Me.LedControl2.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl2.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl2.Location = New System.Drawing.Point(32, 0)
Me.LedControl2.Name = "LedControl2"
Me.LedControl2.Number = 0
Me.LedControl2.TabIndex = 1
Me.LedControl2.TabStop = False
Me.LedControl2.Text = "LedControl2"
'
'LedControl3
'
Me.LedControl3.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl3.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl3.Location = New System.Drawing.Point(64, 0)
Me.LedControl3.Name = "LedControl3"
Me.LedControl3.Number = 10
Me.LedControl3.TabIndex = 2
Me.LedControl3.TabStop = False
Me.LedControl3.Text = "LedControl3"
'
'LedControl4
'
Me.LedControl4.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl4.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl4.Location = New System.Drawing.Point(96, 0)
Me.LedControl4.Name = "LedControl4"
Me.LedControl4.Number = 0
Me.LedControl4.TabIndex = 3
Me.LedControl4.TabStop = False
Me.LedControl4.Text = "LedControl4"
'
'LedControl5
'
Me.LedControl5.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl5.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl5.Location = New System.Drawing.Point(128, 0)
Me.LedControl5.Name = "LedControl5"
Me.LedControl5.Number = 0
Me.LedControl5.TabIndex = 4
Me.LedControl5.TabStop = False
Me.LedControl5.Text = "LedControl5"
'
'LedControl6
'
Me.LedControl6.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl6.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl6.Location = New System.Drawing.Point(160, 0)
Me.LedControl6.Name = "LedControl6"
Me.LedControl6.Number = 10
Me.LedControl6.TabIndex = 5
Me.LedControl6.TabStop = False
Me.LedControl6.Text = "LedControl6"
'
'LedControl7
'
Me.LedControl7.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl7.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl7.Location = New System.Drawing.Point(192, 0)
Me.LedControl7.Name = "LedControl7"
Me.LedControl7.Number = 0
Me.LedControl7.TabIndex = 6
Me.LedControl7.TabStop = False
Me.LedControl7.Text = "LedControl7"
'
'LedControl8
'
Me.LedControl8.Dock = System.Windows.Forms.DockStyle.Left
Me.LedControl8.ForeColor = System.Drawing.SystemColors.ControlText
Me.LedControl8.Location = New System.Drawing.Point(224, 0)
Me.LedControl8.Name = "LedControl8"
Me.LedControl8.Number = 0
Me.LedControl8.TabIndex = 7
Me.LedControl8.TabStop = False
Me.LedControl8.Text = "LedControl8"
'
'LEDClock
'
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LedControl8, Me.LedControl7, Me.LedControl6, Me.LedControl5, Me.LedControl4, Me.LedControl3, Me.LedControl2, Me.LedControl1})
Me.Name = "LEDClock"
Me.Size = New System.Drawing.Size(256, 32)
Me.ResumeLayout(False)
End Sub
#End Region
<Editor(GetType(LEDTypeEditor), GetType(UITypeEditor))> _
Public Property Time() As String
Get
Return mTime
End Get
Set(ByVal Value As String)
If IsValid(Value) = True Then
mTime = Value
Me.LedControl1.Number = CInt(mTime.Substring(0, 1))
Me.LedControl2.Number = CInt(mTime.Substring(1, 1))
Me.LedControl4.Number = CInt(mTime.Substring(3, 1))
Me.LedControl5.Number = CInt(mTime.Substring(4, 1))
Me.LedControl7.Number = CInt(mTime.Substring(6, 1))
Me.LedControl8.Number = CInt(mTime.Substring(7, 1))
Me.Invalidate()
End If
End Set
End Property
Private Function IsValid(ByVal s As String) As Boolean
If s.Length <> 8 Then Return False
If s.Substring(2, 1) <> ":" Or s.Substring(5, 1) <> ":" Then Return False
Dim ss As String
ss = s.Substring(0, 2)
If IsNumeric(ss) = False Then Return False
If CInt(ss) > 23 Then Return False
ss = s.Substring(3, 2)
If IsNumeric(ss) = False Then Return False
If CInt(ss) > 59 Then Return False
ss = s.Substring(6, 2)
If IsNumeric(ss) = False Then Return False
If CInt(ss) > 59 Then Return False
Return True
End Function
Public Sub [Stop]()
stoped = True
End Sub
Public Sub Start()
stoped = False
End Sub
Public Sub Reset()
Me.Time = "00:00:00"
End Sub
Sub MyThreadProc()
If Me.DesignMode = False Then
Do While flag = False
If stoped = False Then
Me.LedControl8.Inrease()
If Me.LedControl8.Number = 0 Then
If Me.LedControl7.Number < 5 Then
Me.LedControl7.Inrease()
Else
Me.LedControl7.Number = 0
Me.LedControl5.Inrease()
If Me.LedControl5.Number = 0 Then
If Me.LedControl4.Number < 5 Then
Me.LedControl4.Inrease()
Else
Me.LedControl4.Number = 0
Me.LedControl2.Inrease()
If Me.LedControl2.Number = 0 Then
If Me.LedControl1.Number < 2 Then
Me.LedControl1.Inrease()
Else
Me.LedControl1.Number = 0
End If
End If
If Me.LedControl2.Number = 4 And Me.LedControl1.Number = 2 Then
Me.LedControl2.Number = 0
Me.LedControl1.Number = 0
End If
End If
End If
End If
End If
oThread.Sleep(1000)
End If
Loop
End If
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Me.LedControl1.Height = Me.Height
Me.LedControl2.Height = Me.Height
Me.LedControl3.Height = Me.Height
Me.LedControl4.Height = Me.Height
Me.LedControl5.Height = Me.Height
Me.LedControl6.Height = Me.Height
Me.LedControl7.Height = Me.Height
Me.LedControl8.Height = Me.Height
Me.LedControl1.Width = Me.LedControl1.Height
Me.LedControl2.Width = Me.LedControl2.Height
Me.LedControl3.Width = Me.LedControl3.Height
Me.LedControl4.Width = Me.LedControl4.Height
Me.LedControl5.Width = Me.LedControl5.Height
Me.LedControl6.Width = Me.LedControl6.Height
Me.LedControl7.Width = Me.LedControl7.Height
Me.LedControl8.Width = Me.LedControl8.Height
Me.Width = 8 * Me.Height
End Sub
Protected Overrides Sub OnForeColorChanged(ByVal e As System.EventArgs)
Dim c As Control
For Each c In Me.Controls
c.ForeColor = Me.ForeColor
Next
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.