ProgressBar not updating VB.NET

2019-07-03 02:19发布

问题:

I have a progressBar and a timer that controls it. But for some reason the progressBar is not updating however the value of the progressBar it is changing as the timer goes, I did some debug and the progressBar the UI seems to not update, because the value and the timer are working perfectly. Here is my code

     Private Sub timerReserve_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerReserve.Tick
         If progressBar1.Value = progressBar1.Maximum Then
             timerReserve.Stop()
             ....(database updates)
         Else
             countdown +=1 
             progressBar1.Value += 1
         End If
     End Sub

I don't know what is going on, it should work fine ....

Thanks in advance

回答1:

In your Progress bar properties set the STEP property to the same size as the INCREMENT that you are making (you are making +=1 increments)

And then in your timer code, FORCE the progress bar to display the changes.

Private Sub timerReserve_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerReserve.Tick
  If progressBar1.Value = progressBar1.Maximum Then
    timerReserve.Stop()
    ....(database updates)
  Else
    countdown +=1 
    progressBar1.Value += 1
    ' ** FORCE UPDATE **
    progressBar1.PerformStep()
  End If
End Sub