使用相同的计时器两次使用进度条

时间:2013-12-27 19:54:14

标签: vb.net

我想逐个使用两个不同按钮的进度条。问题是,在第一个达到最大值后,它将不会再从另一个按钮开始。

以下是代码:

Private Sub CrystalClearButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalClearButton1.Click
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(10)
End Sub

Private Sub CrystalClearButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalClearButton2.Click
    Timer2.Start()
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    ProgressBar1.Increment(10)
End Sub

1 个答案:

答案 0 :(得分:2)

简单的解决方案是每次单击按钮时重置值。

以下是一个例子:

Private Sub CrystalClearButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalClearButton1.Click
    ProgressBar1.Value = 0
    Timer1.Start()
End Sub

此外,您可以确保如果更改进度条上的Minimum属性,而不是设置为0,则可以使用以下代码继续使用此代码(如果您始终要使用0作为最低限度,那么之前的代码将会很好):

ProgressBar1.Value = ProgressBar1.Minimum