‘timer and a picture box control
Option Explicit
Private Const PI = 3.14159265
Private Sub DrawClock()
Static last_time As Date
Dim cx As Single
Dim cy As Single
Dim num As Single
Dim radius As Single
Dim theta As Single
If last_time = Now Then Exit Sub
last_time = Now
picClock.Cls
cx = picClock.ScaleWidth / 2
cy = picClock.ScaleHeight / 2
‘ Hours.
num = 5 * (DatePart(“h”, last_time) + DatePart(“n”, last_time) / 60 + DatePart(“s”, last_time) / 3600)
theta = MinutesToRadians(num)
radius = picClock.ScaleWidth * 0.3
picClock.DrawWidth = 3
picClock.Line (cx, cy)-Step(radius * Cos(theta), -radius * Sin(theta))
‘ Minutes.
num = DatePart(“n”, last_time)
theta = MinutesToRadians(num)
radius = picClock.ScaleWidth * 0.3
picClock.DrawWidth = 2
picClock.Line (cx, cy)-Step(radius * Cos(theta), -radius * Sin(theta))
‘ Seconds.
num = DatePart(“s”, last_time)
theta = MinutesToRadians(num)
radius = picClock.ScaleWidth * 0.4
picClock.DrawWidth = 1
picClock.Line (cx, cy)-Step(radius * Cos(theta), -radius * Sin(theta))
End Sub
Private Sub DrawFace()
Dim r1 As Single
Dim r2 As Single
Dim r3 As Single
Dim cx As Single
Dim cy As Single
Dim i As Integer
Dim theta As Single
picClock.AutoRedraw = True
cx = picClock.ScaleWidth / 2
cy = picClock.ScaleHeight / 2
r1 = picClock.ScaleWidth * 0.45
r2 = picClock.ScaleWidth * 0.4
r3 = picClock.ScaleWidth * 0.35
For i = 1 To 60
theta = MinutesToRadians(i)
If i Mod 5 = 0 Then
picClock.Line (cx + r1 * Cos(theta), cy + r1 * Sin(theta))-(cx + r3 * Cos(theta), cy + r3 * Sin(theta))
Else
picClock.Line (cx + r1 * Cos(theta), cy + r1 * Sin(theta))-(cx + r2 * Cos(theta), cy + r2 * Sin(theta))
End If
Next i
picClock.Picture = picClock.Image
End Sub
Private Function MinutesToRadians(ByVal num As Single) As Single
MinutesToRadians = (15 – num) * 2 * PI / 60
End Function
Private Sub Form_Load()
DrawFace
End Sub
Private Sub picClock_Paint()
DrawClock
End Sub
Private Sub tmrClock_Timer()
DrawClock
End Sub
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.


















