Solved

Using Windows Forms progress bar - windows forms app

Posted on 2013-05-22
6
231 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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:vbnetcoder
Comment Utility
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
ty
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now