Results 1 to 2 of 2

Thread: [RESOLVED] How to get a progress bar changes from its previous step?

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Resolved [RESOLVED] How to get a progress bar changes from its previous step?

    Hi all

    Consider a progress bar which supposed to indicate a quality for instance.

    How can I get a three state thing which states that this progress bar is fixed, increasing or decreasing?
    In mathematics there's a way in which you calculate differences between current x(t) and its one step retard x(t-1). I wasn't successful to get my previous progress bar value due to "value change" event is not available for this control.

    If anyone know a trick to rectify this matter I will be so much appreciated. ♥ Thanks in advanced

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get a progress bar changes from its previous step?

    It's really remarkable how many people think that the ProgressBar control is magic. It's not. It is simply a visual representation of a ratio. That's it, that's all. If you want to know whether the Value property increased, decreased or remained the same when you last set it then you do the obvious thing: you compare the old value to the new value. That's it, that's all. It's your code that changes that property so just get the value before changing it instead of expecting the control to tell you what it was.

    One option my be to avoid using that property at all and create a custom control with a dedicated method and an extra property:
    vb.net Code:
    1. Public Class ProgressBarEx
    2.     Inherits ProgressBar
    3.  
    4.     Private _previousValue As Integer
    5.  
    6.     Public ReadOnly PreviousValue As Integer
    7.         Get
    8.             Return _previousValue
    9.         End Get
    10.     End Property
    11.  
    12.     Public Sub SetValue(newValue As Integer)
    13.         _previousValue = Value
    14.         Value = newValue
    15.     End Sub
    16.  
    17. End Class
    You can then use that instead of the regular ProgressBar, call SetValue instead of setting the Value property directly and then get PreviousValue in the ValueChanged event handler. Of course, if you're going to do that, you could also move the calculation inside as well, exposing the change direction via a property of an Enum type.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width