title: VB.NET Progress Bar
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5714159/net-progressbar-not-updating">.NET progressbar not updating</a>  </p>
  </blockquote>
  
  
  
  <p>I built a progress bar class that shows the progress in my  for loops. Here's the code for the progress bar class:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Here's how I would use it in a for loop:</p>
  
  <pre><code>Dim pb As New ProgressBar
  pb.ProgressBarSetup(5000, "Test")
  
  For i As Integer = 0 To 5000 - 1
        pb.IncProg()
  Next
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Is there any other ways to achieve a better visually appealing progress bar?</p>