2013-11-21 39 views
1

我一直在嘗試使LolTimer但這並不重要。 由於某些原因,當我點擊btnStartDragon時,兩個計時器都開始運行。 如果我點擊btnStartBaron,這隻會啓動BaronTimer。2定時器同時啓動 - VB.Net

我希望你能幫助我這個代碼(其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

你有太多的處理程序:

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 
0

退房此行的末尾:

Private Sub BtnStartBaron_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStartBaron.Click, btnStartDragon.Click 

我懷疑你不想要那裏的第二個。