Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Make an analog clock with a shaped form This example shows how to make an analog clock with a shaped form in Visual Basic 6. analog, clock, shaped form, time, move form Multimedia, Graphics, Utilities

Thanks to Dipak Auddy.

This clock sits on a form shaped to fit the clock. Click and drag the form to move it. Click the "X" to close it.

This example also draws thicker, tapering hands than other examples. The following code draws the face.

```Private Sub Timer1_Timer()

Dim Angle, PX, PY, OX, OY, WX, WY

P1.Cls
'Get Hr Angle...
Angle = (180 - (Hour(Now) * 6) * 5 - (Minute(Now) * 6) _
/ 12) * 3.1415 / 180
'Hr. point
PX = X + (hWidth * Sin(Angle))
PY = Y + (hWidth * Cos(Angle))
'Opposite side
OX = X - (Sin(Angle) * 100)
OY = Y - (Cos(Angle) * 100)
'Hand width
WX = Sin(Angle + PI2) * 90
WY = Cos(Angle + PI2) * 90
'Draw Hr. hand...
P1.Line (OX, OY)-(PX, PY), vbYellow    ' From opposite
' side to pointer
P1.Line -(OX + WX, OY + WY), vbBlue  ' To one opposite
' side
P1.Line -(OX - WX, OY - WY), vbBlue  ' To other
' opposite side
P1.Line -(PX, PY), vbBlue           ' Back to pointer
P1.Circle (X, Y), 50, vbYellow
'Get Min Angle...
Angle = (180 - (Minute(Now) * 6)) * 3.1415 / 180
'Min point
PX = X + (mWidth * Sin(Angle))
PY = Y + (mWidth * Cos(Angle))
'Opposite side
OX = X - (Sin(Angle) * 100)
OY = Y - (Cos(Angle) * 100)
'Hand width
WX = Sin(Angle + PI2) * 90
WY = Cos(Angle + PI2) * 90
'Draw Min. hand...
P1.Line (OX, OY)-(PX, PY), vbYellow    ' From opposite
' side to pointer
P1.Line -(OX + WX, OY + WY), vbMagenta  ' To one
' opposite side
P1.Line -(OX - WX, OY - WY), vbMagenta  ' To other
' opposite side
P1.Line -(PX, PY), vbMagenta           ' Back to pointer
P1.Circle (X, Y), 50, vbYellow
'Get Sec Angle...
Angle = (180 - (Second(Now) * 6)) * 3.1415 / 180
'Draw Sec. hand...
P1.Line (X, Y)-(X + (sWidth * Sin(Angle)), Y + (sWidth _
* Cos(Angle))), vbRed
End Sub```