Oke sekarang kita akan membuat aplikasi stopwatch biasa di VB.NET, ikuti langkah-langkahnya sebagai berikut :
1. Buat Design form kurang lebih sebagai berikut :
2. Coding ini di jendela code nya :
1: Public Class Form1
2: Dim milseconds, seconds, minutes, hours As Integer
3:
4: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
5: Timer1.Interval = 10
6: Timer1.Start()
7: End Sub
8: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
9: Me.Close()
10: End Sub
11:
12: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
13: Timer1.Enabled = False
14: End Sub
15:
16:
17: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
18: Timer1.Stop()
19: End Sub
20:
21: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
22: If milseconds = 60 Then
23: milseconds = 0
24: seconds = seconds + 1
25: End If
26: If seconds = 60 Then
27: If milseconds = 60 Then
28: milseconds = 0
29: seconds = 0
30: minutes = minutes + 1
31: End If
32: End If
33: If minutes = 60 Then
34: If seconds = 60 Then
35: If milseconds = 60 Then
36: milseconds = 0
37: seconds = 0
38: minutes = 0
39: hours = hours + 1
40: End If
41: End If
42: End If
43: milseconds = milseconds + 1
44: TextBox1.Text = Format(hours, "00") & ":" & Format(minutes, "00") & ":" & Format(seconds, "00") & ":" & Format(milseconds, "00")
45: End Sub
46:
47: Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
48: Timer1.Stop()
49: TextBox1.Clear()
50: End Sub
51: End Class
3. Maka sudah berhasil deh.. enak yah kalau tinggal copas mah.. hehehe….tampilannya sebagai berikut :
Source codenya bisa di download disini
0 Komentar
Post a Comment