当前位置 : 主页 > 编程语言 > c语言 >

vb.net – Timer Inside Label

来源:互联网 收集:自由互联 发布时间:2021-06-24
我正在尝试将倒数计时器放入我的程序中,但是当我运行程序时,它不会倒计时.它跳到一个,就是这样. Private Sub CompactTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompactTim
我正在尝试将倒数计时器放入我的程序中,但是当我运行程序时,它不会倒计时.它跳到一个,就是这样.

Private Sub CompactTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompactTimer.Tick
    Dim Time As Integer = 11
    Do Until Time = 0
        ClockLabel.Text = "Compacting database in: " & Time
        Time -= 1
    Loop
End Sub

我也启动了计时器并在Form_Load routuine中将间隔声明为500.

摆脱循环并在范围外声明Time变量.

Dim Time As Integer = 11

Private Sub CompactTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) _
                              Handles CompactTimer.Tick
  If Time >= 0 Then
    ClockLabel.Text = "Compacting database in: " & Time
    Time -= 1
  Else
    CompactTimer.Stop
  End If
End Sub
网友评论