VB.net中如何用timer控件编出一个简单的倒计时器?

要求按正常的时间一秒一秒的减,倒计时结束时有提示。请高手指点,回答尽量详细点,有代码最好!谢谢…

Dim tCount As Integer '用来计数

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       tCount = 10
       Timer1.Interval = 1000 '每秒执行一次
       Timer1.Enabled = True
   End
Sub

   Private Sub
Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
       tCount -= 1
       If tCount = 0 Then
           MessageBox.Show("时间到")
           Timer1.Enabled = False
       End If
   End
Sub

温馨提示:内容为网友见解,仅供参考
第1个回答  2013-06-30
Public Class Form1

Dim tCount As Integer '用来计数

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tCount = 10
Timer1.Interval = 1000 '每秒执行一次
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
tCount -= 1
If tCount = 0 Then
MsgBox("时间到")
Timer1.Enabled = False
End If
End Sub
End Class本回答被网友采纳
第2个回答  2013-06-30
全局变量

每次--就对了
第3个回答  2013-06-30
用Timer控件吧,设置1秒执行1次。然后直接在Timer中写代码,将全全局的值来 减减1,如果值为0,则停止Timer 跳出提示框
以下示例:
int Tatal = 100;
Timer.Inveral = 1000;
Timer_()
{
if ( Tatal == 0)
{
MessageBox.Show("完成!");
Timer.Stop();
}
else
{
Tatal --;
}
}
相似回答