就这个倒计时代码
求VB倒计时代码
- 提问者网友:焚苦与心
- 2021-07-25 15:23
- 五星知识达人网友:轻熟杀无赦
- 2021-07-25 16:21
给一个很简单的例子你参考一下
控件有label1和timer1
Private Sub Form_Load()
Label1.Caption = "100"
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Label1.Caption - 1
End Sub
- 1楼网友:酒醒三更
- 2021-07-25 19:32
只会做简单的
Dim a# Private Sub Command1_Click() Timer1.Enabled = True Label1.Caption = "开始倒记时" End Sub Private Sub Form_Load() Timer1.Enabled = False Timer1.Interval = 1000 Command1.Caption = "记时开始" Text1.Text = "" Label1.Caption = "请输入时间(单位:秒)" End Sub
Private Sub Timer1_Timer() a = Val(Text1.Text) a = a - 1 Text1.Text = a End Sub
- 2楼网友:山有枢
- 2021-07-25 18:17
以下是代码:
Private Declare Function GetTickCount Lib "kernel32" () As Long Dim stoptime As Long Private Sub Combo1_Click() HScroll1.Value = CInt(Combo1.Text) Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub Combo2_Click() HScroll2.Value = CInt(Combo2.Text) Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub Combo3_Click() HScroll3.Value = CInt(Combo3.Text) Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub Command1_Click()
stoptime = GetTickCount + CLng(Combo1.Text) * 3600 * 1000 + CLng(Combo2.Text) * 60 * 1000 + CLng(Combo2.Text) * 1000 Timer1.Enabled = True
End Sub
Private Sub Command2_Click() Timer1.Enabled = False End Sub
Private Sub Command3_Click() End End Sub
Private Sub Form_Load() Dim i As Integer For i = 0 To 59 Combo2.AddItem Format(i, "00"), i Combo3.AddItem Format(i, "00"), i Next i For i = 0 To 23 Combo1.AddItem Format(i, "00"), i Next i Combo1.ListIndex = 0 Combo2.ListIndex = 0 Combo3.ListIndex = 0 HScroll1.Min = 0 HScroll1.Max = 23 HScroll2.Min = 0 HScroll2.Max = 59 HScroll3.Min = 0 HScroll3.Max = 59 Timer1.Enabled = False Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub HScroll1_Scroll() Combo1.ListIndex = HScroll1.Value Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text End Sub
Private Sub HScroll2_Scroll() Combo2.ListIndex = HScroll2.Value Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub HScroll3_Scroll() Combo3.ListIndex = HScroll3.Value Label2.Caption = Combo1.Text + ":" + Combo2.Text + ":" + Combo3.Text
End Sub
Private Sub Timer1_Timer() Dim currentTime As Long Dim displayTime As Long currentTime = GetTickCount
displayTime = stoptime - currentTime If displayTime > 0 Then Label2.Caption = Format((displayTime \ 1000) \ 3600, "00") & ":" & Format(((displayTime \ 1000) \ 60) Mod 60, "00") & ":" & Format((displayTime \ 1000) Mod 60, "00") End If End Sub
- 3楼网友:孤独入客枕
- 2021-07-25 17:09