[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Using Windows Forms progress bar - windows forms app

Posted on 2013-05-22
Medium Priority
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?
Question by:vbnetcoder
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39188851
If you're running in the main UI thread:
Some Loop
    ... code ...
    ProgressBar1.Value = x
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!

Author Comment

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
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).
Technology Partners: 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

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?
LVL 86

Accepted Solution

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

Open in new window


Author Closing Comment

ID: 39190709

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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