[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Timer Control - Countdown

Posted on 2006-11-07
4
Medium Priority
?
247 Views
Last Modified: 2010-04-23
Hi

I would like to close a form after 5 minutes, on the form load event I have:

Timer1.Interval = 300000
Timer1.Enabled = True

and the tick:

Timer1.Enabled = False
Me.Close()

How do I populate a label with a real time countdown of the time left before the form closes?

Thanks
0
Comment
Question by:weight01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Accepted Solution

by:
newyuppie earned 2000 total points
ID: 17894785
if you are using VB2005 you could take advantage of the new Stopwatch class:

imports system.diagnostics
dim sw as new stopwatch
sw.start


also you would need to set a new timer with the interval set to 1 second

dim Timer2 as new Timer
timer2.interval = 1000

and in the tick for this timer:
dim sec as integer = sw.elapsedmilliseconds * 1000
label1.text = sec.tostring()
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17894838
i forgot you needed a countdown, the code above will do a "countup". anyway, you only need to modify the code in the tick event of timer2 to a substraction like:

dim sec as integer = 5 - sw.elapsedmilliseconds * 1000
label1.text = sec.tostring()


on the other hand, if you dont have VB2005 you could use a more rudimentary approach, such as establishing a variable when your form loads that stores the value of the date and time the form opened, and then using the timer's tick to read the substraction from NOW and that variable you have set up before.

in the Load event:

Dim _dtStarted as DateTime = DateTime.Now

using the tick event of the TImer2 i commented before:
  dim tsElapsed as TimeSpan = 5 - DateTime.Now.Subtract(_dtStarted)
  label1.text = tsElapsed.TotalSeconds.ToString()



0
 
LVL 1

Author Comment

by:weight01
ID: 17897038
Many Thanks

Your help is appreciated
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17897883
thanks for the grade.
NY
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question