我一直在尝试制作LolTimer,但这并不重要。 出于某种原因,当我点击btnStartDragon时,两个计时器都开始运行。 如果我点击btnStartBaron,这只会启动BaronTimer。
我希望你能帮我解决这个问题(在vb.Net中):
Public Class Loltimer
'Dragon Timer-----------------------------------------------------------------------------------------------------------------------------------
Private Sub Loltimer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Timers
Timer1.Interval = 1000 '// tick every second.
'// textbox1 = Hours, textbox2 = Minutes, textbox3 = Seconds
txtDragMin.Text = "6" : txtDragSec.Text = "00"
Timer2.Interval = 1000 '// tick every second.
'// textbox1 = Hours, textbox2 = Minutes, textbox3 = Seconds
txtBaronMin.Text = "6" : txtBaronSec.Text = "00"
End Sub
Private Sub btnStartDragon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartDragon.Click
'Start timer
If Timer1.Enabled = False Then
Timer1.Start()
btnStartDragon.Text = "Running"
txtDragMin.Visible = True
txtDragSec.Visible = True
lblDragonSpawn.Visible = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If txtDragMin.TextLength < 2 Then txtDragMin.Text = "0" & txtDragMin.Text '// format from "0" to "00"
'// verify Minutes.
If txtDragMin.Text > "00" And txtDragSec.Text = "00" Then
txtDragMin.Text -= 1
txtDragSec.Text = "60"
End If
If txtDragSec.TextLength < 2 Then txtDragSec.Text = "0" & txtDragSec.Text '// format from "0" to "00"
'// verify Seconds.
If txtDragSec.Text > "00" Then txtDragSec.Text -= 1
'Spawned
If txtDragMin.Text = "00" And txtDragSec.Text = "0" Then
Timer1.Enabled = False
lblDragonSpawn.Visible = True
txtDragMin.Visible = False
txtDragSec.Visible = False
txtDragMin.Text = "6" : txtDragSec.Text = "00"
btnStartDragon.Text = "Start"
End If
End Sub
'--------------------------------------------------------------------------------------------------------------------------------
'Baron Timer-----------------------------------------------------------------------------------------------------------------------------------
Private Sub BtnStartBaron_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStartBaron.Click, btnStartDragon.Click
'Start timer
If Timer2.Enabled = False Then
Timer2.Start()
BtnStartBaron.Text = "Running"
txtBaronMin.Visible = True
txtBaronSec.Visible = True
lblBaronspawn.Visible = False
End If
End Sub
Private Sub timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If txtBaronMin.TextLength < 2 Then txtBaronMin.Text = "0" & txtBaronMin.Text '// format from "0" to "00"
'// verify Minutes.
If txtBaronMin.Text > "00" And txtBaronSec.Text = "00" Then
txtBaronMin.Text -= 1
txtBaronSec.Text = "60"
End If
If txtBaronSec.TextLength < 2 Then txtBaronSec.Text = "0" & txtBaronSec.Text '// format from "0" to "00"
'// verify Seconds.
If txtBaronSec.Text > "00" Then txtBaronSec.Text -= 1
'Spawned
If txtBaronMin.Text = "00" And txtBaronSec.Text = "0" Then
Timer2.Enabled = False
lblBaronspawn.Visible = True
txtBaronMin.Visible = False
txtBaronSec.Visible = False
txtBaronMin.Text = "6" : txtBaronSec.Text = "00"
BtnStartBaron.Text = "Start"
End If
End Sub
结束班
答案 0 :(得分:0)
查看此行的结尾:
Private Sub BtnStartBaron_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStartBaron.Click, btnStartDragon.Click
我怀疑你不想要第二个。
答案 1 :(得分:0)
你有太多的处理程序:
Private Sub BtnStartBaron_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles BtnStartBaron.Click, btnStartDragon.Click
尝试将其更改为:
Private Sub BtnStartBaron_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles BtnStartBaron.Click