2013-03-18 3 views
0

나는 ... 문제보기 남은 시간은 시간 범위

문제는 내가 음의 값을 얻을 만 남아있는 타이머와 함께하는 작업의 remainig 시간을 보여 주려 얻고있다

은 예입니다 10000 밀리 초 (10 초)의 동작 : "-"시간과 분의 스틸 incorrects 값 시간 범위에서 문자 ...

어쨌든

enter image description here

나는를 제거하는 경우

RemainingTime = EndTime.Subtract(Now) 

그렇지 않으면, 내가 아니에요 : 여기

Dim time_out as integer = 60000 ' 'Milisegundos 

    Dim StartTime As DateTime ' Tiempo inicio 
    Dim EndTime As DateTime ' Tiempo final 

    Dim ElapsedTime As TimeSpan ' Tiempo transcurrido 
    Dim RemainingTime As TimeSpan ' Tiempo restante 


    ' Elapsed Time 
#Region " Elapsed Time Function " 

    Public Function Print_Elapsed_Time() 
     If StartTime.ToString = "01/01/0001 0:00:00" Then 
      StartTime = Now 
      StartTime = StartTime.AddSeconds(-1) 
     End If 
     ElapsedTime = Now().Subtract(StartTime) 
     Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(ElapsedTime.TotalHours)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalMinutes)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalSeconds)) Mod 60) 
    End Function 
#End Region 

#Region " Remaining Time Function " 

    Public Function Print_Remaining_Time() 
     If EndTime.ToString = "01/01/0001 0:00:00" Then 
      EndTime = Now 
      EndTime = EndTime.AddMilliseconds(Time_Out - 1000) 
     End If 
     RemainingTime = Now().Subtract(EndTime) 
     Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(RemainingTime.TotalHours)) Mod 60, CInt(Math.Floor(RemainingTime.TotalMinutes)) Mod 60, CInt(Math.Floor(RemainingTime.TotalSeconds)) Mod 60).Replace("-", "") 
    End Function 

#End Region 

답변

1

원하는 타이머와 두 개의 레이블을 사용 십초에서 카운트 다운의 예입니다 어떻게 초기화했는지 확인해 보았습니다.하지만이 변경 작업을 수행했습니다.

Dim StartTime As DateTime = DateTime.MinValue ' Tiempo inicio 
Dim EndTime As DateTime = DateTime.MinValue ' Tiempo final 

If StartTime = DateTime.MinValue Then ' ... etc ' 

하지만 아마도 플래그 또는 무엇인가가 재설정을 알리는 더 좋은 방법입니다.

+0

쉬운 해결책을 가져 주셔서 감사합니다! – ElektroStudios

2

내가 종료 시간에 대한 생각
'example - countdown from 10 secs 
Dim countdown As New TimeSpan(0, 0, 10) 
Dim stpw As New Stopwatch 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    If stpw.IsRunning Then 
     stpw.Stop() 
     Timer1.Stop() 
    Else 
     stpw.Stop() 
     stpw.Reset() 
     stpw.Start() 
     Timer1.Interval = 100 
     Timer1.Start() 
    End If 
End Sub 

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
    'label1 - elapsed time 
    'label2 - time remaining 
    If stpw.Elapsed <= countdown Then 
     Label1.Text = stpw.Elapsed.ToString 
     Label2.Text = (countdown - stpw.Elapsed).ToString 
    Else 
     stpw.Stop() 
     Label1.Text = countdown.ToString 
     Label2.Text = "00:00:00" 
    End If 
End Sub 
+0

고맙습니다! – ElektroStudios