11
Reply

c# countdown using a timer

Kasper

Kasper

Nov 11 2009 8:38 AM
16.9k
Hello everyone,
I hope I put it in the right section, but I'm rather sure I did.

I have a few problems with my timer.

- It will not go in to the "if (timer1.Interval == 1)"-loop.
- I have no clue how to convert an integer to time, but in a way where I can easily substract 1 second, and go from :00 to :59. (I am assuming I' m going to have to do this converting an integer to a different standard).
- Either the timer, or the progress bar which I use to check the timer with, is awfully "chunky" when it comes to short countings, it seems really unaccurate. (Adjusting the MarqueeAnimationSpeed does not help, I have tried(not sure if this was stupid or not, but I'd like to hear what this actually does, then)).
- Also the .Interval seems NOT to be in milliseconds in my program for some odd reason.

You can see the code below, thanks in advance.

      private void timer1_Tick(object sender, EventArgs e)
        {
            if (timer1.Interval == 1)
            {
                timer1.Stop();

                buttonStart.Text = "Start";
                buttonStop.Enabled = false;

                progressBar1.Value = progressBar1.Minimum;

                System.Windows.Forms.MessageBox.Show("The timer has run out of time");
            }

            if (progressBar1.Value < 100)
            {
                progressBar1.Value++;

                //labelShowTime.Text = ();
                labelShowProgressBarValue.Text = (Convert.ToString(progressBar1.Value) + "%");
            }
        }


Answers (11)