?
Solved

Using Windows Forms progress bar - windows forms app

Posted on 2013-05-22
6
Medium Priority
?
245 Views
Last Modified: 2013-05-23
I have progress bar on my applications.  It should update as a for next loop progresses.

How do i do it?
0
Comment
Question by:vbnetcoder
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39188851
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!
0
 

Author Comment

by:vbnetcoder
ID: 39188975
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
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39189051
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).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vbnetcoder
ID: 39189081
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?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 39189094
Something like...
Dim percentage As Integer
For i As Integer = 1 to TotalCount

    ' ... some work ...

    percentage = i / TotalCount * 100
    ProgressBar1.Value = percentage ' <-- assuming default Min = 0, Max = 100
    Application.DoEvents()
Next

Open in new window

0
 

Author Closing Comment

by:vbnetcoder
ID: 39190709
ty
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question