vb.net 我想编一个计时器,计时器显示格式00:00:00 (只能用一个label)怎么做?

如题所述

Dim hour, min, sec As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始计时" Then
Command1.Caption = "停止计时"
Timer1.Enabled = True
Else
If Command1.Caption = "停止计时" Then
Command1.Caption = "开始计时"
Timer1.Enabled = False
End If
End If
End Sub
Private Sub Form_Load()
hour = 0
min = 0
sec = 0
Label1.Caption = Format(hour, "00") & ":" & Format(min, "00") & ":" & Format(sec, "00")
End Sub
Private Sub Timer1_Timer()
sec = sec + 1
If sec > 59 Then
sec = 0
min = min + 1
If min > 59 Then
min = 0
hour = hour + 1
End If
End If
Label1.Caption = ""
Label1.Caption = Format(hour, "00") & ":" & Format(min, "00") & ":" & Format(sec, "00")
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答