Hello~ I'm having a little problem on how to make a timer which include minutes and seconds. The design of the form goes like this:
Another condition here is when the timer goes down, the interval gets faster.
Please help me~
Hello~ I'm having a little problem on how to make a timer which include minutes and seconds. The design of the form goes like this:
Another condition here is when the timer goes down, the interval gets faster.
Please help me~
A compact, reliable pattern for a VB.NET Windows Forms countdown is to keep an accurate elapsed clock (Stopwatch) and compute the remaining TimeSpan each tick, while smoothly reducing the Timer interval as time runs out. ’s countdown-class suggestion is a good direction for reuse, and is correct that changing the Timer interval will speed the countdown — the example below combines those ideas while avoiding cumulative drift.
' class-level
Private totalMs As Integer
Private stopwatch As System.Diagnostics.Stopwatch
Private baseInterval As Integer = 1000 ' start tick ~1s
Private minInterval As Integer = 100 ' do not go below this (ms)
Private Sub StartCountdown(minutes As Integer, seconds As Integer)
totalMs = (minutes * 60 + seconds) * 1000
stopwatch = New System.Diagnostics.Stopwatch()
stopwatch.Start()
Timer1.Interval = baseInterval
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim elapsed = CInt(stopwatch.ElapsedMilliseconds)
Dim remainingMs = Math.Max(0, totalMs - elapsed)
Dim ts = TimeSpan.FromMilliseconds(remainingMs)
LabelTime.Text = ts.ToString("mm\:ss")
If remainingMs = 0 Then
Timer1.Stop()
stopwatch.Stop()
Exit Sub
End If
Dim ratio = If(totalMs > 0, remainingMs / CDbl(totalMs), 0)
Timer1.Interval = CInt(Math.Max(minInterval, baseInterval * ratio))
End Sub Notes and cautions: use TimeSpan.ToString("mm\:ss") for minutes:seconds. Keep minInterval reasonably large (50–150 ms) because Windows timer resolution and UI responsiveness degrade at very small intervals. For server-side ASP.NET pages, run the countdown in client-side JavaScript (or use SignalR) — server timers cannot update the browser UI directly. For very high timing precision (audio sync or sub-10 ms), use high-resolution timers rather than System.Windows.Forms.Timer.
Jump to Post— NetJunkie 29may help you.
may help you.
Hello~ I'm having a little problem on how to make a timer which include minutes and seconds. The design of the form goes like this:
Another condition here is when the timer goes down, the interval gets faster.
Please help me~
dim i as integer=0
timer1= i
label1.Text = "Remaining time:" + CStr(2500 - j) + "seconds"
i = i + 1
If i > 5000 Then
Timer1.Enabled = False
commandbutton1.text=stop
End If
Thank you so much! I'm going to study the notes!
Thank you so much! I'm going to study the notes!
it's ok
timer properties= 5000 interval
5000 means 5 seconds.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.