摘要:利用Timer做簡單的倒數計時
瀏覽文章時看到下面這篇如何編寫 Visual Basic Timer ,是詢問如何做倒數顯示的功能,之前還沒有玩過這樣的功能,這邊簡單測試了一下,還滿好玩的;下面是測試的程式碼,可以參考看看
Dim StartTime As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
StartTime = Now
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = (Now - StartTime).TotalSeconds
TextBox2.Text = (DateTimePicker1.Value - Now).TotalSeconds
End Sub
範例程式碼也可以在這邊下載