基本上,当我继续进入下一个表单时,我的计时器仍在运行,我该如何阻止它? 我已经使用过“Timer1.Enabled = False”
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
MsgBox("Sorry, your time has expired. Please try again.", vbOKOnly, "Warning")
Me.Close()
End Sub
答案 0 :(得分:0)
我认为您使用的是Windows计时器。
如果这是真的,那么您的第一个消息框会产生不必要的副作用,以在程序的消息队列中累积许多Tick事件。
您停留在视频中的时间越长,显示的消息框将显示更多消息框,因为消息在队列中累积
您可以尝试使用全局表单变量
来解决这种情况Dim timeElapsed as Boolean
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
if timeElapsed = False then
timeElapsed = true ' It is important that you set immediatly this to true
MsgBox("Sorry, your time has expired. Please try again.", vbOKOnly, "Warning")
Me.Close()
Dim t = CType(sender, Timer)
t.Elapsed = false
End If
End Sub
另请查看Hans Passant关于处理定时器的建议