VB中如何timer 控件进行倒计时

前端之家收集整理的这篇文章主要介绍了VB中如何timer 控件进行倒计时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、程序加载时操作: Private Sub Form_Load() '窗体加载时自动进行
Timer1.Interval = 1000 ‘设置计时周期为1秒注意默认计时单位为毫秒,即1/1000秒

2、定义一个时间变量。可以某控件的Caption属性代替,如Label12.Caption
3、拖放timer控件到程序界面上
4、设置倒计时:双击时钟控件,输入计时规则,如Label12.Caption = Label12.Caption + 1
5、设置当时间值达到某一条件的时候应采取的方法(即动作)。可以用if语句。如if Label12.Caption =60,then Unload Form1,注意块if语句与行if语句的区别

以下是例子:
Private Sub Form_Load() '窗体加载时自动进行以下操作
Timer1.Interval = 1000 '计时频率设为1秒
end sub
Private Sub Timer1_Timer()
Label12.Caption = Label12.Caption - 1 '以秒计时
End Sub
Private Sub CommandSure_Click()
if Label12.Caption =
s = MsgBox("确认提交,取消重填!",1,"提示信息") '弹出对话框
If s = 1 Then
f = MsgBox("提交信息成功,请点击确认退出系统","")
Unload Form1 '窗体关闭
Else
Load Form1 '重新初始化
Form1.Enabled = True '允许重填
Timer1.Enabled = True '继续计时
CommandSure.Enabled = True '确定按钮可用
end if
end sub

原文链接:https://www.f2er.com/vb/257463.html

猜你在找的VB相关文章