先在畫面上拉幾個控制項
TextBox => 輸入「分鍾」,例如: 倒數5分鍾
Button => 開始
Label => 顯示倒數開始
Timer => 跑倒數要用的元件
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = 2
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Dim timer_I As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Label1.Text = timer_I.ToString()
Dim dtime As New TimeSpan(0, timer_I, 0)
Label1.Text = dtime.ToString()
timer_I = timer_I - 1
If timer_I <= 0 Then
Label1.BackColor = Color.Red
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' 計算時間的開始(分鍾)
timer_I = CInt(TextBox1.Text) * 60
' 啟動計時器
Timer1.Enabled = True
' 恢復預設值
Label1.BackColor = Color.FromKnownColor(KnownColor.Control)
End Sub
留言列表