怎么用VB制作一个倒计时?
要求一打开,按“开始”就从3:00开始倒计时,到30秒的时候字条由蓝色变红色。有“暂停”和“继续”的功能~(就是说不需要重新设定时间,一打开就是从一个固定的是时间开始~)...
要求一打开,按“开始”就从3:00开始倒计时,到30秒的时候字条由蓝色变红色。有“暂停”和“继续”的功能~
(就是说不需要重新设定时间,一打开就是从一个固定的是时间开始~) 展开
(就是说不需要重新设定时间,一打开就是从一个固定的是时间开始~) 展开
展开全部
窗体中放入一个Timer1,一个Label1,三个按钮Command1、Command2、Command3
Dim tt As Integer
Private Sub Command1_Click() '开始按钮
tt = 180
Command1.Enabled = False
Command3.Enabled = False
Label1.ForeColor = vbBlue
Label1.Caption = ""
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command2_Click() '暂停按钮
Command2.Enabled = False
Command3.Enabled = True
Timer1.Enabled = False
End Sub
Private Sub Command3_Click() '继续按钮
Command2.Enabled = True
Command3.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If tt <= 30 Then
Label1.ForeColor = vbRed
If tt <= 0 Then
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Timer1.Enabled = False
End If
End If
Label1.Caption = (tt \ 60) & ":" & Format(tt Mod 60, "00")
tt = tt - 1
End Sub
Dim tt As Integer
Private Sub Command1_Click() '开始按钮
tt = 180
Command1.Enabled = False
Command3.Enabled = False
Label1.ForeColor = vbBlue
Label1.Caption = ""
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command2_Click() '暂停按钮
Command2.Enabled = False
Command3.Enabled = True
Timer1.Enabled = False
End Sub
Private Sub Command3_Click() '继续按钮
Command2.Enabled = True
Command3.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If tt <= 30 Then
Label1.ForeColor = vbRed
If tt <= 0 Then
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Timer1.Enabled = False
End If
End If
Label1.Caption = (tt \ 60) & ":" & Format(tt Mod 60, "00")
tt = tt - 1
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
窗体中放置三个Command、三个Label、一个Timer控件,在Form_Load过程中已经说明了控件用途,其中Label1是显示分钟数,Label2是显示秒数,代码如下:
Dim JS As Integer '这里声明了一个全局变量,保存计时数
Private Sub Command1_Click()
Timer1.Enabled = False '停止计时
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True '继续计时
End Sub
Private Sub Command3_Click()
Unload Me '重新计时
Form1.Show
End Sub
Private Sub Form_Load()
Command1.Caption = "暂停" '"暂停"按钮
Command2.Caption = "继续" '"继续"按钮
Command3.Caption = "重新计时" '"重新计时"按钮
Label3.Caption = ":" '显示":" 分隔符
Timer1.Enabled = True '使计时开始
Timer1.Interval = 1000 '计时间隔为1分钟(1000毫秒)
JS = 180 '计时数初始化,180秒即3分钟
End Sub
Private Sub Timer1_Timer()
Dim F As Integer, M As Integer
If JS > 0 Then
JS = JS - 1
If JS <= 30 Then '在小于30秒后,标签底色为红色
Label1.BackColor = &HFF
Label2.BackColor = &HFF
Label3.BackColor = &HFF
End If
F = Int(JS / 60) '计算分钟数
M = JS - F * 60 '计算秒数
Label1.Caption = F '在Label1标签显示分钟数
Label2.Caption = M '在Label2标签显示秒数
Else
Timer1.Enabled = False '如果计时数小于或等于0,不再计时
End If
End Sub
Dim JS As Integer '这里声明了一个全局变量,保存计时数
Private Sub Command1_Click()
Timer1.Enabled = False '停止计时
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True '继续计时
End Sub
Private Sub Command3_Click()
Unload Me '重新计时
Form1.Show
End Sub
Private Sub Form_Load()
Command1.Caption = "暂停" '"暂停"按钮
Command2.Caption = "继续" '"继续"按钮
Command3.Caption = "重新计时" '"重新计时"按钮
Label3.Caption = ":" '显示":" 分隔符
Timer1.Enabled = True '使计时开始
Timer1.Interval = 1000 '计时间隔为1分钟(1000毫秒)
JS = 180 '计时数初始化,180秒即3分钟
End Sub
Private Sub Timer1_Timer()
Dim F As Integer, M As Integer
If JS > 0 Then
JS = JS - 1
If JS <= 30 Then '在小于30秒后,标签底色为红色
Label1.BackColor = &HFF
Label2.BackColor = &HFF
Label3.BackColor = &HFF
End If
F = Int(JS / 60) '计算分钟数
M = JS - F * 60 '计算秒数
Label1.Caption = F '在Label1标签显示分钟数
Label2.Caption = M '在Label2标签显示秒数
Else
Timer1.Enabled = False '如果计时数小于或等于0,不再计时
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-19
展开全部
设定一个长型变量,在窗体的载入事件中为它赋初值。
创建一个timer控件,设定Interval属性为响应周期,在timer1_timer中让该变量自减。然后用一个分支,若等于0则作出某种动作。
参考例子:
Dim lTime As Long
Sub Form_ Load()
lTime = 100 ’ 100秒倒计时
Timer1.Interval=1000 ' 每秒发生一次Timer事件
End Sub
Sub Timer1_Timer()
lTime = lTime - 1
Me.Caption = "还有" + Str(lTime) + "秒"!
If lTime = 0 Then
MsgBox "时间已到!"
End If
End Sub
创建一个timer控件,设定Interval属性为响应周期,在timer1_timer中让该变量自减。然后用一个分支,若等于0则作出某种动作。
参考例子:
Dim lTime As Long
Sub Form_ Load()
lTime = 100 ’ 100秒倒计时
Timer1.Interval=1000 ' 每秒发生一次Timer事件
End Sub
Sub Timer1_Timer()
lTime = lTime - 1
Me.Caption = "还有" + Str(lTime) + "秒"!
If lTime = 0 Then
MsgBox "时间已到!"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
来个简单的:
Dim t As Date, iTime As Date
'开始
Private Sub Command1_Click()
Label1.ForeColor = vbBlue
Label1 = "3:00"
iTime = "00:03:00"
Timer1.Interval = 100
Timer1.Enabled = True
t = Time
End Sub
'暂停
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
'继续
Private Sub Command3_Click()
Timer1.Enabled = True
t = Time
End Sub
'倒计时
Private Sub Timer1_Timer()
If Time - t > 1 / 24 / 3600 Then
iTime = iTime - CDate("00:00:01")
Label1 = Right(CStr(iTime), 4)
If Label1 = "0:30" Then Label1.ForeColor = vbRed
If Label1 = "0:00" Then Timer1.Interval = 0
t = Time
End If
End Sub
Dim t As Date, iTime As Date
'开始
Private Sub Command1_Click()
Label1.ForeColor = vbBlue
Label1 = "3:00"
iTime = "00:03:00"
Timer1.Interval = 100
Timer1.Enabled = True
t = Time
End Sub
'暂停
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
'继续
Private Sub Command3_Click()
Timer1.Enabled = True
t = Time
End Sub
'倒计时
Private Sub Timer1_Timer()
If Time - t > 1 / 24 / 3600 Then
iTime = iTime - CDate("00:00:01")
Label1 = Right(CStr(iTime), 4)
If Label1 = "0:30" Then Label1.ForeColor = vbRed
If Label1 = "0:00" Then Timer1.Interval = 0
t = Time
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询