Disabling .NET progressbar animation when changing value?

后端 未结 5 1344
灰色年华
灰色年华 2020-11-27 05:56

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

5条回答
  •  粉色の甜心
    2020-11-27 05:57

    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
    

提交回复
热议问题