用VB编写一个倒计数窗体程序。

来源:百度知道 编辑:UC知道 时间:2024/06/01 14:22:09
其功能是,用户在文本框中输入一个自然数,然后单击“倒计数”按纽,文本框中的数字就没隔0.5秒就逐次减1,当减到0时,倒计数停止。
不要写的太深奥,我是刚学VB的!!!!太深奥的我看不懂!

在窗体中添加一个文本框text1,按钮Command1和计数器Timer1,其中Timer1的间隔(就是I开头那个)设成500(就是500毫秒),Enabled设为False,双击Timer1,在里面打
if text1.text<=0 then
timer1.enabled=false
else
text1.text=text1.text-1
end if
然后在按钮的命令中打
timer1.enabled=true
就可以了

建三个控件Text1、Command1、Timer1
代码就直接复制下面的就行了

Private Sub Command1_Click()
If IsNumeric(Text1.Text) Then
Timer1.Interval = 500
Timer1.Enabled = True
Else
msg = MsgBox("请输入数字")
Text1.SetFocus
End If
End Sub

Private Sub Form_Load()
Timer1.Interval = 0
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
If Text1.Text > 0 Then
Text1.Text = Text1.Text - 1
Else
Timer1.Interval = 0
Timer1.Enabled = False
End If
End Sub