VB.NET进度条 [英] VB.NET Progress Bar

查看:201
本文介绍了VB.NET进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:
.NET进度栏不更新


我建立了一个进度条类显示我的for循环的进展。这里是进度条类的代码:

pre $ Public Class frmProgress
Private Sub frmProgress_Load(sender As System.Object, e As System.EventArgs)处理MyBase.Load
progressBar.Minimum = 0
End Sub
$ b $ Public Sub ProgressBarSetup(ByRef Maximum As Integer,ByRef Title As String)
progressBar.Maximum = Maximum
progressBar.Value = 0
Me.Text = Title
Me.Show()
End Sub

Public Sub IncProg ()
progressBar.Value + = 1
Application.DoEvents()

如果progressBar.Value = progressBar.Maximum Then
Me.Close()
End If
End Sub
End Class

以下是我将如何使用它在一个for循环中:

  Dim pb As New ProgressBar 
pb.ProgressBarSetup(5000,Test)

For i As Integer = 0 To 5000 - 1
pb.IncProg()
Next

这个问题是一个视觉问题。它完成了高达70-85%的完整进度条,然后关闭。关闭时,进度条的值和最大值是相等的,但是只填充到它的长度的四分之三左右。



我试着用progressBar.Refresh()而不是Application.DoEvents(),但它减慢了很多的进步 - 并仍然给我相同的结果。

是否有任何其他方式来实现更好的视觉有趣的进度条?

解决方案

在Windows 7上看到这种效果是正常的。问题是当您将值设置为X时,在接下来的0.5-1秒之内到达这个位置。所以如果你的行动发生得很快,你只能看到50-80%。解决方案是先设置一个更高的值,然后递减到你想要的。就像这样:

  progressBar.Value + = 2 
progressBar.Value - = 1
code>

另外不要忘记暂时增加最大值,否则可能会出现异常,例如从4999增加到5000 (你不能设置为5001)。

Possible Duplicate:
.NET progressbar not updating

I built a progress bar class that shows the progress in my for loops. Here's the code for the progress bar class:

Public Class frmProgress
Private Sub frmProgress_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    progressBar.Minimum = 0
End Sub

Public Sub ProgressBarSetup(ByRef Maximum As Integer, ByRef Title As String)
    progressBar.Maximum = Maximum
    progressBar.Value = 0
    Me.Text = Title
    Me.Show()
End Sub

Public Sub IncProg()
    progressBar.Value += 1
    Application.DoEvents()

    If progressBar.Value = progressBar.Maximum Then
        Me.Close()
    End If
End Sub
End Class

Here's how I would use it in a for loop:

Dim pb As New ProgressBar
pb.ProgressBarSetup(5000, "Test")

For i As Integer = 0 To 5000 - 1
      pb.IncProg()
Next

The issue is a visual problem. It completes up to 70-85% of the complete progress bar and then closes. On closure, the progress bar value and maximum values are equal, yet the bar is only filled to about three quarters of it's length.

I tried using progressBar.Refresh() instead of Application.DoEvents() but it slows down the progress by a lot - and still gives me the same result.

Is there any other ways to achieve a better visually appealing progress bar?

解决方案

Seeing this effect is normal on Windows 7. Problem is when you set a value to X, it slides to this position over the next 0.5-1 second. So if your action is happening fast, you will only see it full at 50-80%. Solution is to set first to a higher value and then decrement to the one you want. Something like this:

progressBar.Value += 2
progressBar.Value -= 1

And also don't forget to increase maximum temporarily, or you may get an exception, for example, when incrementing from 4999 to 5000 (you cannot set to 5001).

这篇关于VB.NET进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆