Guest User

Guest User

  • Tech Writer
  • 10
  • 0

c# countdown using a timer

Nov 11 2009 8:38 AM
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.
  1. private void timer1_Tick(object sender, EventArgs e)  
  2. {  
  3.     if (timer1.Interval == 1)  
  4.     {  
  5.         timer1.Stop();  
  6.   
  7.         buttonStart.Text = "Start";  
  8.         buttonStop.Enabled = false;  
  9.   
  10.         progressBar1.Value = progressBar1.Minimum;  
  11.   
  12.         System.Windows.Forms.MessageBox.Show("The timer has run out of time");  
  13.     }  
  14.   
  15.     if (progressBar1.Value < 100)  
  16.     {  
  17.         progressBar1.Value++;  
  18.   
  19.         //labelShowTime.Text = ();  
  20.         labelShowProgressBarValue.Text = (Convert.ToString(progressBar1.Value) + "%");  
  21.     }  
  22. }  

Answers (11)