ProgressBar 未更新 VB.NET

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30420027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:08:57  来源:igfitidea点击:

ProgressBar not updating VB.NET

vb.netprogress-bar

提问by ocespedes

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

我有一个进度条和一个控制它的计时器。但是由于某种原因,progressBar 没有更新,但是progressBar 的值随着计时器的变化而变化,我做了一些调试,UI 似乎没有更新progressBar,因为值和计时器工作正常。这是我的代码

     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

提前致谢

回答by Zeddy

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)

在您的进度条属性中,将 STEP 属性设置为与您正在制作的 INCREMENT 相同的大小(您正在制作 +=1 增量)

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