2013-12-24 67 views
0

我在程序中有一個計時器,計時器觸發進度條,當進度條完成時,它使標籤可見。問題在於標籤在進度條結束之前變得可見。這是我的代碼。Vb.net計時器不能像我想要的那樣工作

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    If ComboBox1.SelectedItem = "Microsoft Office" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(5) 
    End If 
    If ComboBox1.SelectedItem = "Windows 8" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(1) 
    End If 
    If ComboBox1.SelectedItem = "Sony Vegas Pro 12.0" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(10) 
    End If 
    If ComboBox1.SelectedItem = "Minecraft Premium" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(20) 
    End If 
    If ProgressBar1.Value = ProgressBar1.Maximum Then 
     Timer1.Stop() 
     ProgressBar1.Value = 0 
     ProgressBar1.Visible = False 
     Button1.Visible = False 
     Button2.Visible = True 
    End If 
    If ComboBox1.SelectedItem = "Microsoft Office" Then 
     Label4.Visible = True 
     Exit Sub 
    End If 
    If ComboBox1.SelectedItem = "Windows 8" Then 
     Label5.Visible = True 
     Exit Sub 
    End If 
    If ComboBox1.SelectedItem = "Sony Vegas Pro 12.0" Then 
     Label6.Visible = True 
     Exit Sub 
    End If 
    If ComboBox1.SelectedItem = "Minecraft Premium" Then 
     Label7.Visible = True 
     Exit Sub 
    End If 
End Sub 

如果我能得到,爲什麼標籤出現應答之前的進度條變爲可見這將是偉大的!

+0

WHICH標籤?你只是根據組合框的選擇設置了幾個,而不是**是否完成了步驟欄。順便說一句,combobox的選擇可能會改變滴答,也許看起來像一個bug取決於這是什麼 – Plutonix

回答

0

問題在於您的If聲明的邏輯。最後三個使得其中一個Label可見的評估和執行每個滴答。如果您只希望在進度條完成後對它們進行評估,請嘗試更多類似的方法:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    If ComboBox1.SelectedItem = "Microsoft Office" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(5) 
    End If 
    If ComboBox1.SelectedItem = "Windows 8" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(1) 
    End If 
    If ComboBox1.SelectedItem = "Sony Vegas Pro 12.0" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(10) 
    End If 
    If ComboBox1.SelectedItem = "Minecraft Premium" Then 
     ProgressBar1.Visible = True 
     ProgressBar1.Increment(20) 
    End If 
    If ProgressBar1.Value = ProgressBar1.Maximum Then 
     Timer1.Stop() 
     ProgressBar1.Value = 0 
     ProgressBar1.Visible = False 
     Button1.Visible = False 
     Button2.Visible = True 

     If ComboBox1.SelectedItem = "Microsoft Office" Then 
      Label4.Visible = True 
      Exit Sub 
     End If 
     If ComboBox1.SelectedItem = "Windows 8" Then 
      Label5.Visible = True 
      Exit Sub 
     End If 
     If ComboBox1.SelectedItem = "Sony Vegas Pro 12.0" Then 
      Label6.Visible = True 
      Exit Sub 
     End If 
     If ComboBox1.SelectedItem = "Minecraft Premium" Then 
      Label7.Visible = True 
      Exit Sub 
     End If 
    End If 
End Sub 
+0

我的代碼和你提供的代碼之間有什麼區別? – Coder11

+0

如果ProgressBar1.Value = ProgressBar1.Maximum Then已經移到了設置標籤可見性的三個If語句之後,確保它們只在進度條到達其行時才運行結束。重要的是要記住,一個'If'語句的執行不會阻止其發生後發生的其他任何事情,除非這些其他語句包含在另一個塊(例如'Else'或'ElseIf'塊)中。 – Adrian

相關問題