1, program load operation: Private Sub form_load () ' form is loaded automatically
timer1.interval = 1000 ' Set the tick period to 1 seconds note The default timing unit is milliseconds, or 1/1000 seconds
2. Define a time variable. Can be substituted for the Caption property of a control, such as Label12.caption
3. Drag and drop the timer control to the program interface
4, set the countdown: Double-click the clock control, enter the timing rules, such as Label12.caption = label12.caption + 1
5. Set the method (i.e. action) to be taken when the time value reaches a certain condition. You can use the IF statement. If Label12.caption =60,then Unload Form1, note the difference between a block if statement and a line if statement
Here is an example:
Private Sub form_load () ' form loads automatically when the following actions are
timer1.interval = 1000 ' chronograph frequency set to 1 seconds
End Sub
Private Sub timer1_timer ()
label12.caption = Label12.caption-1 ' in seconds
End Sub
Private Sub Commandsure_click ()
If label12.caption =
s = MsgBox ("Confirm the submission, cancel the refill!") ", 1," prompt message ") ' Pop-up dialog box
If s = 1 Then
f = MsgBox ("Submit message successfully, please click to confirm exit System", 0, "")
Unload Form1 ' form off
Else
Load Form1 ' reinitialization
form1.enabled = True ' Allow refill
timer1.enabled = True ' Continue timing
commandsure.enabled = True ' OK button available
End If
End Sub
How to Countdown Timer control in VB