简体   繁体   English

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

[英]How to auto repeat counter in label and call an event when reach maximum count.

I want to make a program that has a counter until 5 and when reach 5 it will auto click a button and must count back from 0 - 5 again and again every time reach 5.我想制作一个程序,它有一个直到 5 的计数器,当达到 5 时,它会自动单击一个按钮,并且每次达到 5 时都必须从 0 - 5 一次又一次地倒数。

below is my code in timer click.下面是我的计时器点击代码。

    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

End Class结束类

here is my solution to my question:

when the timer tick i auto increment my label 1- 5 and when it reach 5 it will return to 0 and count again 1 - 5. and repeat.当计时器滴答时,我会自动增加我的标签 1-5,当它达到 5 时,它将返回 0 并再次计数 1-5。并重复。 then can do something after reach 0. hope can help然后可以在达到 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使滚动条达到VB.Net中的最大值 - How to get a scroll bar to reach the maximum in VB.Net 当此值为今天的日期时,如何在Label上显示特定值的计数 - How to display the count of specific value on Label when this value is the today date 如果文本框具有字符串,则显示msgbox,但(。)不计数。 视觉基础 - if textbox has string then show msgbox but the (.) doesnt count. visual basic 如何计算Visual Basic中的最大行数 - How to count Maximum rows in Visual Basic 到达方法结束后如何引发事件? - How to Raise an Event Once I Reach End of Method? 如何在每次页面加载到asp.net(vb)中递减的label中实现一个计数器? - How to implement a counter in label which decrements every time page is loaded in asp.net(vb)? 如何在10秒后自动隐藏标签并在标签隐藏重定向到〜/ Default.aspx之后? - How to auto hide label after 10 sec and after label hide redirect to the ~/Default.aspx? 如何通过按钮事件在动态数组中查找最大值和最小值 - How to find the maximum and minimum numbers in a dynamic array through a button event 为什么在vb.net中某个表格的控件的最大位置是32767? (启用表单的自动滚动属性时) - why is the maximum position of control in a form in vb.net is 32767? (when auto scroll property of the form is enabled) 触发事件时在函数调用中引发异常 - Raise exception in function call when event is triggered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM