如何在标签中自动重复计数器并在达到最大计数时调用事件。

时间:2018-02-12 15:53:53

标签: vb.net visual-studio-2010

我想制作一个具有计数器直到5的程序,当达到5时,它会自动点击一个按钮,并且每次达到5时必须一次又一次地从0到5计数。

下面的

是我点击计时器的代码。

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As 
    System.EventArgs) Handles Timer2.Tick

    Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
    If ts.TotalMilliseconds > 0 Then
        lblTime2.Text = ts.ToString("ss")
    Else
        lblTime2.Text = "00"
        Timer2.Stop()
        btnRefresh.PerformClick()
    End If


End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
    messagebox.show 'me dot click'
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

here is my solution to my question:

当计时器勾选时,我自动递增我的标签1-5,当它达到5时,它将返回0并再次计数1 - 5.并重复。然后可以做到达到0.希望可以帮助

      Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Label1.Text = Label1.Text + 1
    If Label1.Text = "5" Then
        Label1.Text = 0
        btnRefresh.PerformClick()


    End If
End Sub