كود :
Dim Stopwatch As Stopwatch
Dim day = 0, hour = 0, minute = 0, second = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Stopwatch = Stopwatch.StartNew()
Stopwatch.Reset()
NumericUpDown1.Maximum = 100
NumericUpDown2.Maximum = 24
NumericUpDown3.Maximum = 60
NumericUpDown4.Maximum = 60
Label1.Text = "00-00:00:00.000"
Button1.Text = "إبدأ"
Button2.Text = "توقف"
Button3.Text = "إعادة"
Timer1.Interval = 1
End Sub
' Finish() الإنتهاء
Private Sub Finish()
Beep ''<<<<<<<<<<<<<<<<<<<<< صوت تنبيه بالنهاية
MsgBox("إنتهى") ''<<<<<<<<<<<<<<<<<<<<<
End Sub
' Start() البدء
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If New TimeSpan(day, hour, minute, second, 0) <> New TimeSpan(0, 0, 0, 0, 0) Then
Stopwatch.Start()
Timer1.Start()
End If
End Sub
' Pause() التوقف المؤقت
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Stopwatch.Stop()
End Sub
' Reset() الإعادة
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Stopwatch.Reset()
Dim elapsedTime As String = String.Format("{0:00}-{1:00}:{2:00}:{3:00}.{4:000}", day, hour, minute, second, 0)
Me.Label1.Text = elapsedTime
End Sub
' Tick العملية
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Stopwatch IsNot Nothing AndAlso Stopwatch.IsRunning Then
Dim ts1 As TimeSpan = Stopwatch.Elapsed
Dim ts2 As New TimeSpan(day, hour, minute, second, 0)
Dim ts As TimeSpan = ts2 - ts1
If ts1.Duration >= New TimeSpan(day, hour, minute, second, 0) Then
Timer1.Stop()
ts = New TimeSpan(0, 0, 0, 0, 0)
Me.Label1.Text = String.Format("{0:00}-{1:00}:{2:00}:{3:00}.{4:000}", 0, 0, 0, 0, 0)
Finish()
End If
Dim elapsedTime As String = String.Format("{0:00}-{1:00}:{2:00}:{3:00}.{4:000}", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)
Me.Label1.Text = elapsedTime
End If
End Sub
' NumericUpDown value changed تغير قيم الضبط
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles NumericUpDown1.ValueChanged, NumericUpDown2.ValueChanged, NumericUpDown3.ValueChanged, NumericUpDown4.ValueChanged
day = NumericUpDown1.Value
hour = NumericUpDown2.Value
minute = NumericUpDown3.Value
second = NumericUpDown4.Value
End Sub