0

Hello, I have created a timer for my Winforms to tick down from 300 to 0 and then refresh my form. I have used this.refresh when it hits 0 but it doesn't seem to do anything as the label is still the same when it has completed it's timer function. Any ideas how to get it to work?

// Start the timer.
            timeLeft = 300;            
            timer1.Start();

 private void timer1_Tick(object sender, EventArgs e)
        {        
            if (timeLeft > 0)
            {
                timeLeft = timeLeft - 1;
                lblTime.Text = timeLeft + " seconds";
            }
            else if (timeLeft == 0)
            {
                //Timer runs out of time and refresh form
                RefreshDirSize1();
                RefreshDirSize2();
                RefreshDirSize3();
                RefreshDirSize4();
                this.Refresh();
            }

Edited by Nick Evan: added code-tags

2
Contributors
2
Replies
6
Views
6 Years
Discussion Span
Last Post by Mattisc
0

Please use code tags if you post code.
What label are you talking about?
else if (timeLeft == 0) is a bit meaningless, you can just as well say else

0

lblTime.Text....

I have come up with a solution but not sure if it is sound coding but it works.. I have put TimeLeft = 300 again, when the timer hits 0 so it goes back to 300.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.