Click here to Skip to main content
15,357,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have inserted a timer to my form, but i want every tick of the timer's time remaining to display on a label as string like a countdown, but instead the timer's remaining time is subtracted by 1 and goes no further. Any recommendations?, snippets?, or blog post. Thank you

What I have tried:

Have tried using a label validation declaration but it doer work.
Posted
Updated 1-Mar-21 20:22pm
Comments
Maciej Los 2-Mar-21 2:15am
   
What have you tried till now?
What is "label validation"?

Take a look at past answers: How to program a countdown timer in VB.NET[^]
   
Without the relevant code we can;t tell you how to fix this.
But ... this is what I'd do.
Set up a Timer on a half-second interval, and handle the Tick event.
Set up a class level DateTime variable called targetTime.
When you start the countdown, set targetTime to the current date and time plus the interval you want:
C#
targetTime = DateTIme.Now.AddSeconds(30)
And start the Timer.
In the Tick event handler, display the difference:
VB
Dim interval As Integer = (targetTime - DateTime.Now).TotalSeconds

If interval <= 0 Then
    interval = 0
    myTimer.[Stop]()
End If

timerDisplay.Text = interval.ToString()
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900