展开全部
很容易!
建3个TEXT(分别显示时、分、秒),1个定时器(设1秒),2个按钮(开始倒计时和退出)。
TEXT里分别写入预设的时间。如果是2小时,就分别写2、00、00。
定时器响应里:
秒-1,如果为负,置59,同时分钟位-1,....
类推。直至3个位都为0。
特意给你写个简单的代码,时间到有语音提示等,不管你信不信,反正我测试通过了。
Dim sec, min, h
Private Sub Command1_Click()
Timer1.Enabled = True
h = Text1.Text
min = Text2.Text
sec = Text3.Text
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1.BackColor = &HFFFF00
Timer1.Enabled = False
Timer1.Interval = 1000
Text1.Text = 2
Text2.Text = "00"
Text3.Text = "00"
Command2.Caption = "退出"
Command1.Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If
If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If
If h > 0 Then
h = h - 1
Else: Timer1.Enabled = False
CreateObject("SAPI.SpVoice").Speak "GAME OVER!"
Form1.BackColor = &HFF
End If
End If
End If
Text1.Text = h
Text2.Text = min
Text3.Text = sec
End Sub
建3个TEXT(分别显示时、分、秒),1个定时器(设1秒),2个按钮(开始倒计时和退出)。
TEXT里分别写入预设的时间。如果是2小时,就分别写2、00、00。
定时器响应里:
秒-1,如果为负,置59,同时分钟位-1,....
类推。直至3个位都为0。
特意给你写个简单的代码,时间到有语音提示等,不管你信不信,反正我测试通过了。
Dim sec, min, h
Private Sub Command1_Click()
Timer1.Enabled = True
h = Text1.Text
min = Text2.Text
sec = Text3.Text
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1.BackColor = &HFFFF00
Timer1.Enabled = False
Timer1.Interval = 1000
Text1.Text = 2
Text2.Text = "00"
Text3.Text = "00"
Command2.Caption = "退出"
Command1.Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If
If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If
If h > 0 Then
h = h - 1
Else: Timer1.Enabled = False
CreateObject("SAPI.SpVoice").Speak "GAME OVER!"
Form1.BackColor = &HFF
End If
End If
End If
Text1.Text = h
Text2.Text = min
Text3.Text = sec
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询