VB.NET 在其计时器滴答中停止计时器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32580128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:27:38  来源:igfitidea点击:

VB.NET Stop a timer in its timer tick

vb.nettimer

提问by Chatter Box

How do I stop a timer in its own timer tick? This is the code so far:

如何在自己的计时器滴答中停止计时器?这是到目前为止的代码:

Private Sub replyTimer_Tick(sender As Object, e As EventArgs) Handles replyTimer.Tick
    MsgBox("Hello!")
    Me.replyTimer.Stop()
End Sub

But for some reason, it doesn't stop.

但出于某种原因,它并没有停止。

回答by Mousa Alfhaily

First of all:

首先:

The enabled property for the timer must be "False", so the timer doesn't start when form loaded.

计时器的 enabled 属性必须为“False”,因此加载表单时计时器不会启动。

and you have to make sure that: in the other parts of your code there is no command or loop to restart the timer.

并且您必须确保:在代码的其他部分中没有命令或循环来重新启动计时器。

and to stop the timer... you just need this code :

并停止计时器......你只需要这个代码:

Private Sub replyTimer_Tick(sender As Object, e As EventArgs) Handles replyTimer.Tick
     replyTimer.Stop()    
     MsgBox("Hello!")
End Sub

so every time the timer starts : the message will pop, and the timer will not restart.

所以每次计时器启动时:消息会弹出,并且计时器不会重新启动。

To start the timer again write:

要再次启动计时器,请编写:

replytimer.start()

i hope my answer was useful to you :)

我希望我的回答对你有用:)