如何每隔x秒发生一次事件? VB.NET

时间:2015-10-25 00:14:30

标签: vb.net winforms timer

如何在VB.NET中每隔x秒创建一次事件回调?

1 个答案:

答案 0 :(得分:2)

  

如何让它每10秒钟向我的计数器添加一个?

Public Class Form1

    Private Counter As Integer = 0

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.Text = Counter.ToString
        Me.Timer1.Interval = TimeSpan.FromSeconds(10).TotalMilliseconds
        Me.Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Counter = Counter + 1
        Label1.Text = Counter.ToString
    End Sub

End Class