2
Cara Membuat Aplikasi Stopwatch / Penghitung Waktu dengan VB.NET
Aplikasi penghitung waktu adalah aplikasi yang sering kita temui dalam
aktivitas sehari-hari. Alat Penghitung waktu secara komersil dikenal dengan
nama Stopwatch. Penasaran bagaimana cara membuatnya?
Berikut adalah langkah-langkah untuk membuat stopwatch dengan VB.NET :
Jalankan visual basic.net-mu
Buka Project baru
Desain form1 seperti gambar dibawah ini :
Atur properties control menurut table dibawah ini :
No.
|
Kontrol
|
Properties
|
1.
|
Label
|
Name : Label1
Text : Timoresse Stopwatch
|
2.
|
Picturebox
|
Name : PictureBox1
|
3.
|
Button
|
Name : Button1
Text : Start
|
4.
|
Button
|
Name : Button2
Text : Pause
|
5.
|
Button
|
Name : Button3
Text : Reset
|
6.
|
Timer
|
Name : Timer1
|
7.
|
TextBoxt
|
Name : TextBox1
Text :
|
Masukan Kode Berikut kedalam Program tersebut :
Public Class Form1
Dim milseconds, seconds, minutes, hours As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Gambar stopwatch1.jpg di masukan kedalam folder \bin\Debug
PictureBox1.ImageLocation = Application.StartupPath & "\stopwatch1.jpg"
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Timer1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Stop()
TextBox1.Clear()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If milseconds = 60 Then
milseconds = 0
seconds = seconds + 1
End If
If seconds = 60 Then
If milseconds = 60 Then
milseconds = 0
seconds = 0
minutes = minutes + 1
End If
End If
If minutes = 60 Then
If seconds = 60 Then
If milseconds = 60 Then
milseconds = 0
seconds = 0
minutes = 0
hours = hours + 1
End If
End If
End If
milseconds = milseconds + 1
TextBox1.Text = Format(hours, "00") & ":" & Format(minutes, "00") & ":" & Format(seconds, "00") & ":" & Format(milseconds, "00")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 10
Timer1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
End Class
Saatnya testing program, silahkan tekan F5.
Tekan Start untuk mulai melakukan
penghitung waktu.
Terima kasih,
Semoga Bermanfaat,
Download source code program dan tutorial PDF klik disini

