您的位置:首页 > 编程语言 > VB

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

2015-04-30 00:00 357 查看
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("提交信息成功,请点击确认退出系统", 0, "")
Unload Form1 '窗体关闭
Else
Load Form1 '重新初始化
Form1.Enabled = True '允许重填
Timer1.Enabled = True '继续计时
CommandSure.Enabled = True '确定按钮可用
end if
end sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: