2016-12-12 38 views
0

那麼,我做了一個計時器(具體來說,它是一個網吧咖啡館獨立定時器是在Visual Basic 2010與目標框架.NET Framework 4.5定時器不工作在VB.NET 2010

現在,有一個小型的形式,顯示您:time start, time out, minutes (total minutes of your rent), and your time left.我已經成功地得到時的內容在我的Main.vb開始,一樣的時間了,和分鐘(以後看到的代碼參考) 。現在,我試圖讓時間不斷更新,每分鐘都在不斷更新。輸出如下:「33 minutes left

Main.vb

 If TextBox1.Text = My.Settings.userpass Then 
      MessageBox.Show("Enjoy!", "...") 
      dtFuture = DateTime.Now.AddMinutes(min.Text).ToString("hh:mm:ss") 
      Limited.currtime.Text = DateTime.Now.ToString("hh:mm:ss") 
      Limited.timeout.Text = dtFuture 
      Limited.minutes.Text = min.Text 
      Limited.Timer1.Interval = 1 
      Limited.Timer1.Start() 
      Limited.Show() 
      Me.Close() 
     Else 
      ... 
     End If 

Limited.vb(這是當你限制了形式時,不開放時間):

Public Class Limited 
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) 
     Dim foo As New TimeSpan 
     Dim dtfuture As New DateTime 
     Dim timecurrent As TimeSpan = dtfuture.Subtract(DateTime.Now) 
     Dim timeCheckIn As String = Format(timecurrent, "HH:mm:ss") 
     dtfuture = DateTime.Now.AddMinutes(minutes.Text) 

     If Timer1.Interval <> 100 Then Timer1.Interval = 100 
     If DateTime.Now > dtfuture Then 
      timelft.Text = "Time's up!" 
      block.Show() 
      Timer1.Stop() 
      Me.Close() 
     Else 
      foo = dtfuture - DateTime.Now 
      ts = TimeSpan.Parse(timeCheckIn) 
      timelft.Text = String.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", _ 
           foo.Hours, foo.Minutes, foo.Seconds, foo.Milliseconds) 
     End If 
    End Sub 

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click 

    End Sub 
    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick 
     Label3.Text = TimeOfDay 
    End Sub 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     ' hide app in to the taskbar 

    End Sub 
End Class 
+1

和你的問題是什麼? –

+0

嗯,我有房租開始時間和時間,他將要停止,但定時器或「標籤」不顯示出來。 – astronomicalXoom

+0

而且它們在表單的前面肯定是可見的,而不是隱藏在任何東西后面?字體顏色不同於背景等? –

回答

0

基本上你dtfuture沒有在Timer1_Tick正確的值。我不確定ts是什麼意思,所以你可能需要自己修改那部分。

Private Sub Timer1_Tick(sender As Object, e As EventArgs) 
    Dim foo As New TimeSpan 

    ' This is when time will be up. 
    Dim dtfuture As DateTime = DateTime.Parse(timeout.Text) 

    ' I have no idea what these variables do. Not sure what "ts" below means.  
    Dim timecurrent As TimeSpan = dtfuture.Subtract(DateTime.Now) 
    Dim timeCheckIn As String = Format(timecurrent, "HH:mm:ss") 

    ' The If in original code is unnecessary. 
    Timer1.Interval = 100 

    If DateTime.Now > dtfuture Then 
     timelft.Text = "Time's up!" 
     block.Show() 
     Timer1.Stop() 
     Me.Close() 
    Else 
     foo = dtfuture - DateTime.Now 
     ts = TimeSpan.Parse(timeCheckIn) 
     timelft.Text = String.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", _ 
          foo.Hours, foo.Minutes, foo.Seconds, foo.Milliseconds) 
    End If 
End Sub 
+0

我嘗試過了,它顯示一個錯誤:「‘System.TimeSpan’的值不能被轉換爲‘日期’」 – astronomicalXoom

+0

@astronomicalXoom對不起,應該是'DateTime.Parse'。我更新了答案。 – jetstream96