设计一个倒计时的时钟单击命令按钮,从10秒开始每1秒在标签框中输出“10,9,8........0,开始”。
打开VB ,在form1 上放置一下command、label1和一个timer 控件
输入以下代码
Dim ts As Integer
Private Sub Command1_Click()
ts = 10
Label1。
Caption = 10
Timer1。 Enabled = True
End Sub
Private Sub Timer1_Timer()
ts = ts - 1
Label1。
Caption = ts
If ts = 0 Then
Label1。Caption = "开始"
Timer1。 Enabled = False
End If
End Sub
。
添加一个计时器一个按钮一个标签之后加入这些代码就行了。
Private Sub Command1_Click()
Label1。Caption = 10
Timer1。
Interval = 1000
End Sub
Private Sub Timer1_Timer()
Label1。 Caption = Label1。Caption - 1
If Label1。
Caption = -1 Then
Label1。Caption = "开始"
Timer1。Interval = 0
End If
End Sub。