Jason Paradis
asked on
Configuring a ProgressBar to increase depending on length taken after buttonclick
I have added a ProgressBar and Timer to my project but it's behaving strangely. When I press a button it just increments the progress bar by 1 until it finishes regardless of how long the buttonclick event took. I would like to have it increment and fill to 100 when the event finishes.
Here is my code for the bar under my buttonclick event:
Here is the rest of the code in the timer sub:
How do I make the progress bar dynamically increase depending on the length of time it takes to complete the event and then fill when it ends?
Here is my code for the bar under my buttonclick event:
Private Sub FixAllButton_Click(ByVal sender As System.Object, e As EventArgs) Handles FixAllButton.Click
MasterProgressBar.Value = 0
MasterTimer.Start()
FixAllButton.Enabled = False
Here is the rest of the code in the timer sub:
Private Sub MasterTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MasterTimer.Tick
MasterProgressBar.Value += 1
If MasterProgressBar.Value = 100 Then
MasterTimer.Stop()
FixAllButton.Enabled = True
End If
End Sub
How do I make the progress bar dynamically increase depending on the length of time it takes to complete the event and then fill when it ends?
We can be more helpful if we know what's in the rest of the button click event.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I guess that would work not to let the ProgressBar to reach 100% in a standard Windows application but if your users ever say that the long running task that the button click event is processing ties up the UI and you try putting that code in a different thread so that the user is free to use the UI you will find out that it really does not work. It also hides the problem by stopping the progress bar before reaching 100.
ASKER
No one provided a solution, just questions. I figured it out myself. It didn't need to be overly complicated. It works perfectly with what I wrote.
I see.
If you are in a loop, you know how many items you have to process and it is therefore easy to show a relatively accurate progress bar.
It is not always that simple!