Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

Using Windows Forms progress bar - windows forms app

I have progress bar on my applications.  It should update as a for next loop progresses.

How do i do it?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

If you're running in the main UI thread:
Some Loop
    ... code ...
    ProgressBar1.Value = x
    Application.DoEvents()
End Loop

Open in new window


You should move the code to a background thread though.  Again, take a look at the BackgroundWorker() control.  It has a ReportProgress() method which fires the ProgressChanged() event.  Search for it...examples abound!
Avatar of vbnetcoder
vbnetcoder

ASKER

how will this code know what percentage of the total was just completed.

For example if the loop is going to be 10 times each time i want to move the bar by a tenth
Since you know how many times your loop is going to iterate, just divide the current iteration  number by the total number and multiply by 100 (a percentage!).  Then leave your progressbar at the default maximum of 100 and set it to the current "percentage" value.

Another option is to set the Maximum property of the progressbar to your desired number then call PerformStep() against it for each one (set the Step to 1).
I not sure i am following you...


I have a variable name TotalCount that is the total amount of time it will loop


What would the code look like?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ty