Click here to download the EXE
Click here to download the Project
Source:
Code:
Imports System.Math
Imports System.Drawing
Public Class Form1
Dim x1, y1, x2, y2 As Integer 'used for the points to draw the second hand line
Dim iSecond As Integer 'used to hold vaule to make the second hand line
Const HandLenght = 60 'used to determine the length of the line
Const xDist = 190 'used to help position the line horizontally
Const yDist = 235 'used to help position the line vertically
Dim Pen As New Pen(Color.Black, 2) 'pen that draws the line
Dim stpWatch As New Stopwatch 'used to count the time
Dim iFix As Integer = 0 'I used this to fix the line blinking everytime the form refreshed
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
stpWatch.Start()
End Sub
Private Sub tClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tClock.Tick
'if the stopwatch isn't counting, don't update the clock
If Not stpWatch.IsRunning Then Exit Sub
'added this to only refresh every second.. it was a quick fix
'as I didnt want to spend forever making it look pretty
If iFix < iSecond Then Refresh()
iFix = iSecond
'sets our iSecond value to that of the stopwatch
iSecond = stpWatch.Elapsed.Seconds
'creates our points to draw the line
x1 = Sin(iSecond * PI / 30 + PI) * HandLenght / 5
y1 = Cos(iSecond * PI / 30) * HandLenght / 5
x2 = Sin(iSecond * PI / 30) * HandLenght
y2 = Cos(iSecond * PI / 30 + PI) * HandLenght
'draws the line onto the form
Me.CreateGraphics.DrawLine(Pen, x1 + xDist, y1 + yDist, x2 + xDist, y2 + yDist)
End Sub
Private Sub tTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tTimer.Tick
'if the stopwatch isn't running then exit the sub
If Not stpWatch.IsRunning Then Exit Sub
'if it is, update the labels with info
lblMilli.Text = stpWatch.Elapsed.Milliseconds
lblSec.Text = stpWatch.Elapsed.Seconds
lblMin.Text = stpWatch.Elapsed.Minutes
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
stpWatch.Stop()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
stpWatch.Reset()
End Sub
End Class