Implementing the Control

Now, you are ready to create your control. First, add the following members to the ClockFaceCtrl class. (You'll implement the StringDraw class shortly.)

Private Shared offset As Integer = 0
Private b24Hours As Boolean = False
Private Const FaceRadius As Integer = 700
Private Const DateRadius As Integer = 900
Private currentTime As DateTime
Private myFont As New Font("Arial", 80)
Private sdToday As StringDraw
Private bForceDraw As Boolean = True

Second, you'll need a timer to drive the automatic updating of the clock. Drag a Timer control onto the ClockFaceCtrl window. Visual Basic automatically creates an object of the System.Windows.Forms.Timer class, and names it Timer1. You don't need to do anything else with it for now; you'll set its Elapsed event in the initialization code.

Third, there are two helper methods you'll need to handle some trigonometry for you, GetCos and GetSin. I'll explain what they do later; for now, you can just type them in.

Private Shared Function _
   GetCos(ByVal degAngle As Single) As Single
    Return CSng(Math.Cos((Math.PI * degAngle / 180.0F)))
End Function 'GetCos

Private Shared Function _
   GetSin(ByVal degAngle As Single) As Single
    Return CSng(Math.Sin((Math.PI * degAngle / 180.0F)))
End Function 'GetSin

Get Programming Visual Basic 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.