473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to count 15 Minutes backwards with a Timer?

Hello!

I would like to count 15 Minutes (in this style: 15:00, 14:59, 14:58 ...)
backwards with a Timer and want to show it on a Label.

The Time is displayed correctly (15:00), but nothing happen.

Did I forgot something??

int Minutes = 15;
int Seconds = 0;

private TimeSpan _tsCountDownTime;

private void timer1_Tick(object sender, System.EventArgs e)
{
TimeSpan tsSecond = new TimeSpan(0,0,1);
_tsCountDownTime.Subtract(tsSecond);
lblCount.Text = _tsCountDownTime.Minutes.ToString() + ":" +
_tsCountDownTime.Seconds.ToString();
}

private void btnStart_Click(object sender, System.EventArgs e)
{
setCountDown(Minutes, Seconds);
tmrCount.Enabled = true;
tmrCount.Start();
}

private void setCountDown(int iMinutes, int iSeconds)
{
TimeSpan tsTemp = new TimeSpan(0, iMinutes, iSeconds);
_tsCountDownTime = tsTemp;
}

Thank you!
Nov 15 '05 #1
2 5553
"Robert Mayer" <Ma*****@web.de> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
Hello!

I would like to count 15 Minutes (in this style: 15:00, 14:59, 14:58 ...)
backwards with a Timer and want to show it on a Label.

The Time is displayed correctly (15:00), but nothing happen.

Did I forgot something??

int Minutes = 15;
int Seconds = 0;

private TimeSpan _tsCountDownTime;

private void timer1_Tick(object sender, System.EventArgs e)
{
TimeSpan tsSecond = new TimeSpan(0,0,1);
_tsCountDownTime.Subtract(tsSecond);
lblCount.Text = _tsCountDownTime.Minutes.ToString() + ":" +
_tsCountDownTime.Seconds.ToString();
}


You probably want to replace the following line:

_tsCountDownTime.Subtract(tsSecond);

with:

_tsCountDownTime = _tsCountDownTime.Subtract(tsSecond);

Erik
Nov 15 '05 #2
Thanks!

Works great now.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: caulker | last post by:
I have a simple Windows Service with a timer (system.timer). The service seems to run just fine when I have the Timer = 1 minute, but when I set the Timer = 15 minutes it only fires once ... then...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
5
by: Flack | last post by:
Hey guys, Here is what I am trying to achieve: I have a grid, and every once in a while the grid will receive a message to add a new row and highlight it (change the backcolor) for five...
13
by: David | last post by:
Hi, Im not sure where to find all the documentation i need for this? I need to timer since a start button has been pushed, and show a counter on a page. If they click stop i want to keep the...
2
by: HeroinNO.4 | last post by:
Hello everyone! Now the latest version of free count down timer source code is available in http://www.fillweb.com/countdown.htm, you can open it in IE and View->Source to see the latest version...
7
by: HeroinNO.4 | last post by:
Hello guys, free count down timer source code has updated to 06/11/27, you can copy the code below and save in a ".htm" file and run it in a browser support javascript 1.1 or later, or you can open...
1
by: Ismail | last post by:
Hello, I have webform and usercotnrol with asp:Timer on it. I am in tick event doing count down of timer. What i want to do is when the countdown is complete stop the timer. I tried...
3
by: silverburgh.meryl | last post by:
Hi, I have a function in my python like this: def callFunc(line, no): # some code And I want to do a performance test like this: for line in f: for i in range(int(count)): t1 =...
2
by: =?Utf-8?B?U3VyZXNoIFJlZGR5?= | last post by:
I am getting a strange problem with IE7 tabs. The web application I am working (developed in ASP.Net, .Net 2.0), will show a popup message with the count down timer 2 minutes before session time...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.