Quang Dinh Luong

Quang Dinh Luong

  • NA
  • 76
  • 18.6k

StopWatch? iN C#? I encountered a problem!

Oct 22 2015 11:56 PM
As the subject, I am making a StopWatch. You know, to learn Timer!
Ok, here's my code: (ms = 1, hour, min, second = 0)
    private void timerDisplay_Tick(object sender, EventArgs e)
        {
            ms++;
            if (ms == 10)
               {
                   sec++;
                   ms = 1;
               }
            txtMilisecond.Text = "." + ms;
            if (sec == 60)
               {
                   min++;
                   sec = 0;
               }
           txtSecond.Text = "" + sec;
           if (min == 60)
              {
                   hour++;
                   min = 0;
              }
              txtMinute.Text = "" + min;
              txtHour.Text = "" + hour;
        }
When I run this, it gets faster and faster than an usal watch!
Anyone knows the problem?
Thanks, 
 

Answers (2)