2012-08-23 2 views
1

나는 옵션을 똑딱 거리며 초시계와 카운트 다운으로 작동하는 크로노 미터 양식 응용 프로그램을 만들려고합니다. 문제는 내가 밀리 초를 그릴 수없는 것입니다. 는 현재의 밀리 초없이 틱 방법은 다음과 같습니다크로노 미터 만들기 C#

private void timer_Tick(object sender, EventArgs e) 
    { 
     if (timespan.TotalSeconds > 0) 
     { 
      timespan = timespan.Add(new TimeSpan(0, 0, -1)); 
      updateNumericUpDowns(); 
     } 
     else 
     { 
      timerCountown.Stop(); 
     } 
    } 

UI를 업데이트하는 방법 :

private void updateNumericUpDowns() 
    { 
     numericUpDownSeconds.Value = Convert.ToInt32(timespan.Seconds); 
     numericUpDownMinutes.Value = Convert.ToInt32(timespan.Minutes); 
     numericUpDownHours.Value = Convert.ToInt32(timespan.Hours); 
    } 

도움말이 감사합니다, TNX 모두!

+0

'timespan'은 어디에 정의되어 있습니까? –

+1

정확하지 않을 것입니다. – SLaks

답변

2

잘 모르겠습니다. 왜 timespan.Milliseconds을 사용하지 않는 것이 좋을까요?

그대로, 시간, 분 및 초를 사용하고 있습니다. 밀리 초를 표시하려면 추가하십시오.

2

밀리 초 해상도의 경우 "timer_Tick"을 신뢰하지 않을 것입니다. 시스템에 부하가 많은 경우 틱이 1 초보다 느리거나 빠를까요? (경과 한 밀리 수에 영향을 미칠 것입니까?) 현재 시간을 알려진 시작 시간과 비교해보십시오.

private DateTime startTime; 

void StartTimer() { 
    startTime = DateTime.Now; 
    //start timer 
} 

private void timer_Tick(object sender, EventArgs e) 
{ 
    var currentTime = DateTime.Now; 
    timespan = currentTime - startTime; //positive 
    bool hasCountdownTerminated = ... //maybe something like timespan < duration + timerResolution 
    if (hasCountdownTerminated) 
    { 
     timerCountown.Stop(); 
    } 
    else 
    { 
     updateNumericUpDowns(); 
    } 
}  

void updateNumericUpDowns() { 
    //use timespan.Milliseconds; 
}