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;            

 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

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


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.