加个timer,两个label,以下是代码:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = Format(Now(), "yyyy-MM-dd HH:mm:ss")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label2.Text = Format(Now(), "yyyy-MM-dd HH:mm:ss")
If DateDiff(DateInterval.Hour, DateTime.Parse(Label1.Text), DateTime.Parse(Label2.Text)) = 3 Then
MsgBox("超过3小时了!", , "信息提示")
Timer1.Enabled = False 'timer终止,不然会一直谈对话框!
End If
End Sub
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Text = Date.Now.ToString("yyyy/MM/dd hh:mm:ss")
Label2.Text = Date.Now.AddHours(3)
Timer1.Enabled = True
Timer1.Interval = 3600000 * 3 '/设置相应时间
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False '/使Timer只起作用一次
MessageBox.Show("到点了")
End Sub
End Class
在工具箱里面拖一个Timer控件
没有看到你的开始计时按钮。可以把放在load里的代码挪到button.click里面