Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27400

VS 2012 Countdown Timer/button

$
0
0
I have found many countdown timers but not one that works the way that I am looking. I am trying to have a countdown timer in a button that will change the text. Once you click "Timer" it changes to the time and counts down from minutes and seconds. It will pull the minutes form textbox. I have seen several examples that changes labels and has multiple textboxes or buttons. I just want something very simple. I have a count up timer that works the way that I want but id prefer a count down.

Heres my count up timer:

Code:


    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If Timer2.Enabled = True Then
            Timer2.Stop()
        Else
            Time = DateTime.Now
            Timer2.Start()

        End If

        If Button4.Text = "Timer" Then
            Button4.Text = ""
        Else
            Button4.Text = "Timer"
        End If
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Dim Difference As TimeSpan = DateTime.Now.Subtract(Time)
        Button4.Text = Difference.Minutes.ToString & ":" & Difference.Seconds.ToString

    End Sub

Im not looking for the straight code however I would appreciate if there are any tutorials or any resources that are known that could point me in the right direction.

Or if possible, is there a way to set a count up limit so that once it reaches say, 45 minutes that it stops or has a msgbox?

Viewing all articles
Browse latest Browse all 27400


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>