I have a lblCountdown with an int value of 60. I want to make the int value of the lblCountDown decrease with seconds until it reaches 0.
This is what I have so far:
private int counter = 60;
private void button1_Click(object sender, EventArgs e)
{
int counter = 60;
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000; // 1 second
timer1.Start();
label1.Text = counter.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
counter--;
if (counter == 0)
timer1.Stop();
label1.Text = counter.ToString();
}
2 : the quotient of a unit divided by 32 : one of 32 equal parts of anything one thirty-second of the total. 3 : thirty-second note.
Easily lose track of time? Try this Google Calendar Lab, which adds a handy countdown timer to your next meeting right in Calendar. You'll always see what event is coming up next, in addition to a countdown to that event. In Google Calendar, head up to the gear icon in the upper-right corner > Settings > Labs.
' You have five seconds. Start counting backward to yourself from five to one, then move," says Robbins. "If you don't move within five seconds, your brain will kill the idea and you'll talk yourself out of doing it."
Use Timer for this
private System.Windows.Forms.Timer timer1;
private int counter = 60;
private void btnStart_Click_1(object sender, EventArgs e)
{
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000; // 1 second
timer1.Start();
lblCountDown.Text = counter.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
counter--;
if (counter == 0)
timer1.Stop();
lblCountDown.Text = counter.ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With