好吧,我正在制作一个计时器(具体来说,它是一个InternetCaféStandaloneTimer ,它位于Visual Basic 2010上,目标框架为 .NET Framework 4.5
现在,有一个迷你表单显示: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
答案 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