countdown in sec.,min. und std.

11/13/2013 19:28 DeinMud#16
Code:
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000
    End Sub
    Private startTime As TimeSpan = New TimeSpan(0, 5, 0)
    Private countDown As TimeSpan = startTime
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        countDown = countDown.Subtract(New TimeSpan(0, 0, 1))
        Label1.Text = String.Format("{0}:{1:00}", countDown.Minutes, countDown.Seconds)
        Timer1.Enabled = Not countDown.Negate = countDown
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Timer1.Enabled Then
            Exit Sub
        End If
        countDown = startTime
        Timer1.Start()
    End Sub
End Class