I realize there are other questions on SO regarding animations and progressbars, but they seem to revolve around getting rid of the animation drawn on top of the progress ba
Now follows a VB.Net 2.0 and higher version of Jonathan Reinharts method SetProgressNoAnimation. I hope this will help other VB developers. The function setProgressBarValue is almost crashproof. Hardware failure can bring it down though.
'''
''' In VB.Net, the value of a progress bar can be set without animation.
''' Set the minimum and the maximum value beforehand.
''' This VB version has been written by EAHMK (Evert Kuijpers) in Tilburg in The Netherlands.
''' See SetProgressNoAnimation in
''' https://stackoverflow.com/questions/5332616/disabling-net-progressbar-animation-when-changing-value/5332770
''' by Jonathan Reinhart, based on the suggestion of David Heffernan.
'''
'''
''' The progress bar that is to present the new value.
'''
'''
''' The new value to present in the progress bar.
'''
Public Function setProgressBarValue(progressBar As ProgressBar,
newValue As Integer) As Exception
Try
' Extremes are not supported.
If newValue < progressBar.Minimum _
Or newValue > progressBar.Maximum _
Or progressBar.Maximum = progressBar.Minimum _
Or progressBar.Maximum = Integer.MaxValue Then
Return New ArgumentException("The value " & CStr(newValue) & " for" _
& " the progress bar '" & progressBar.Name & "' is out of bounds.")
End If
' By field maximumReached also progress bar value progressBar.Maximum is supported.
Dim maximumReached As Boolean = newValue = progressBar.Maximum
If maximumReached Then
progressBar.Maximum += 1
End If
progressBar.Value = newValue + 1
progressBar.Value = newValue
If maximumReached Then
progressBar.Maximum -= 1
End If
' The value has been presented succesfully in the progress bar progressBar.
Return Nothing
Catch ex As Exception
' Returns an exception but does not crash on it.
Return ex
End Try
End Function