How to count 15 Minutes backwards with a Timer?

  • Thread starter Thread starter Robert Mayer
  • Start date Start date
R

Robert Mayer

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!
 
Robert Mayer said:
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
 
Back
Top