以下是VB.net
下面的倒计时。有谁知道如何让它自动启动?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Interval = 1000
If hours_label.Text = "" Then
hours_label.Text = "0"
End If
If minutes_label.Text = "" Then
minutes_label.Text = "0"
End If
If seconds_label.Text = "" Then
seconds_label.Text = "0"
End If
If hours_label.Text = "00" Then
hours_label.Text = "0"
End If
If minutes_label.Text = "00" Then
minutes_label.Text = "0"
End If
If seconds_label.Text = "00" Then
seconds_label.Text = "0"
End If
If seconds_label.Text > "0" Then
seconds_label.Text = seconds_label.Text - 1
End If
If minutes_label.Text > "0" Then
If seconds_label.Text = "0" Then
minutes_label.Text = minutes_label.Text - 1
seconds_label.Text = "59"
End If
End If
If hours_label.Text > "0" Then
If minutes_label.Text = "0" Then
If seconds_label.Text = "0" Then
hours_label.Text = hours_label.Text - 1
minutes_label.Text = "59"
seconds_label.Text = "59"
End If
End If
End If
If seconds_label.Text = "0" Then
If minutes_label.Text = "0" Then
If hours_label.Text = "0" Then
Timer1.Enabled = False
MsgBox("Time is up")
Application.Exit()
End If
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Start.Click
If Start.Text = "Start" Then
Timer1.Enabled = True
Start.Text = "Start"
MsgBox("TIME'S UP")
End If
End Sub
答案 0 :(得分:1)
使用表单的LOAD
事件。
Private Sub Payroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
或者,如果您希望表单模拟按钮的Clicking
,请调用相应的按钮单击子例程。
Private Sub Payroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1_Click(sender, e)
End Sub
在这里,Button1_Click(sender, e)
是具有开始按钮处理程序的子例程的名称。