VB6.0中怎样用按钮控制timer控件的启动、停止和重新开始?
展开全部
创建3个按钮,用默认名字命名
创建一个label控件,名称为label1
创建一个timer控件,名称为timer1
复制下列代码运行即可
Private a As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
a = 0
End Sub
Private Sub Form_Load()
Command1.Caption = "启动"
Command2.Caption = "停止"
Command3.Caption = "重新开始"
Label1.Caption = ""
Timer1.Enabled = 0
Timer1.Interval = 1000 '设定周期为1秒
End Sub
Private Sub Timer1_Timer()
a = a + 1
Label1.Caption = a
End Sub
创建一个label控件,名称为label1
创建一个timer控件,名称为timer1
复制下列代码运行即可
Private a As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
a = 0
End Sub
Private Sub Form_Load()
Command1.Caption = "启动"
Command2.Caption = "停止"
Command3.Caption = "重新开始"
Label1.Caption = ""
Timer1.Enabled = 0
Timer1.Interval = 1000 '设定周期为1秒
End Sub
Private Sub Timer1_Timer()
a = a + 1
Label1.Caption = a
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询