Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seconds CountDown Timer

Tags:

string

c#

timer

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();

    }
like image 786
MizLucid Avatar asked May 31 '11 18:05

MizLucid


People also ask

What is a 30 second?

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.

Does Google have a countdown timer?

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.

How do you count 5 seconds?

' 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."


1 Answers

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();
    }
like image 50
Stecya Avatar answered Oct 04 '22 23:10

Stecya