2个回答
展开全部
'在vb窗口上加入Label1,timer1,command1,然后在代码窗口写入以下代码。
Dim S, M, H
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Label1.Caption = "0:02:00"
'Label1.Font = "Times New Roman"
Command1.Caption = "倒计时"
Timer1.Interval = 1000 '可在属性窗口中完成,1000毫秒为1秒
Dim T_all As String
T_all = TimeValue(Label1.Caption)
H = Hour(T_all)
M = Minute(T_all)
S = Second(T_all)
'MsgBox T_all
End Sub
Private Sub Timer1_Timer()
If S > 0 Then
S = S - 1
End If
If S = 0 And M > 0 Then
M = M - 1
S = 59
End If
If M = 0 And S = 0 And H > 0 Then
H = H - 1
M = 59
S = 59
End If
If H < 0 Then
H = 0
End If
If M < 0 Then
M = 0
End If
Label1.Caption = Format(H, "00") & ":" & Format(M, "00") & ":" & Format(S, "00")
If H = 0 And M = 0 And S = 0 Then
MsgBox "时间到!"
end '或者unload me
End If
End Sub
Dim S, M, H
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Label1.Caption = "0:02:00"
'Label1.Font = "Times New Roman"
Command1.Caption = "倒计时"
Timer1.Interval = 1000 '可在属性窗口中完成,1000毫秒为1秒
Dim T_all As String
T_all = TimeValue(Label1.Caption)
H = Hour(T_all)
M = Minute(T_all)
S = Second(T_all)
'MsgBox T_all
End Sub
Private Sub Timer1_Timer()
If S > 0 Then
S = S - 1
End If
If S = 0 And M > 0 Then
M = M - 1
S = 59
End If
If M = 0 And S = 0 And H > 0 Then
H = H - 1
M = 59
S = 59
End If
If H < 0 Then
H = 0
End If
If M < 0 Then
M = 0
End If
Label1.Caption = Format(H, "00") & ":" & Format(M, "00") & ":" & Format(S, "00")
If H = 0 And M = 0 And S = 0 Then
MsgBox "时间到!"
end '或者unload me
End If
End Sub
参考资料: http://zhidao.baidu.com/question/73030818.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询