[VB.net]倒數計時器

嘗試以VB.net學習撰寫一支倒數計時程式,簡易成果如上圖,code如下列所示。

Public Class Form1
    Private Sub StBt_Click(sender As Object, e As EventArgs) Handles StBt.Click
        PrBar.Value = 0
        TB2.Text = ""
        Timer1.Start()
    End Sub

    Private Sub PaBt_Click(sender As Object, e As EventArgs) Handles PaBt.Click
        Timer1.Stop()
    End Sub

    Private Sub ClBt_Click(sender As Object, e As EventArgs) Handles ClBt.Click
        Timer1.Stop()
        PrBar.Value = 0
        TB2.Text = ""
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim i As Integer
        Dim ratio As Single
        Timer1.Interval = 1000 ' timer單位為1ms,1000指的是set timer1以秒計算
        PrBar.Increment(PrBar.Maximum / TB1.Text) 'progress bar以輸入TB1值呈現比例顯示

        ratio = PrBar.Value / PrBar.Maximum '顯示進度比例於日誌進度中
        TB2.AppendText(DateTime.Now + " 進度 " + ratio.ToString("p2") + Environment.NewLine) '日誌記錄

        If PrBar.Value = PrBar.Maximum Then '如果progress bar已完成,則Timer停止
            Timer1.Stop()
            MsgBox("倒數完畢")
        End If
    End Sub

    Private Sub TB1_TextChanged(sender As Object, e As EventArgs) Handles TB1.TextChanged
        Timer1.Stop()
        PrBar.Value = 0
        TB2.Text = ""
    End Sub
End Class

-----如果文章對您有幫助,打開微信掃一掃,請作者喝杯咖啡。-----

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值