How to implement a visual loop counter as a compliment to the already implemented progress bar. VB.NET Windows Form.


On my windows form I have a progress bar which increments based on a for each loop. Since this works very well, I was hoping to extend the idea to display a realtime numeric representation of what the progress bar is doing. Basically a numeric counter, we've all seen these kind of counters when extracting files, installing programs etc. Well its one of those I am looking for.

I have tried doing this by trying to update the text property of a label after every loop but for some reason this does not work until the last loop. I think this is to do with threading, but please advise.

I would be very grateful for any help on this problem.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Hi jazz__man,

See the below example. The use of "Application.DoEvents" causes the control to fully draw at each iteration, thereby updating the Progressbar and the Label.


        For i As Integer = 1 To 100
            ProgressBar1.Value += 1
            Label1.Text = ProgressBar1.Value & "%"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jazz__manAuthor Commented:
All I needed was these two lines..

Superb!! Have a nice day.


Wayne Taylor (webtubbs)Commented:

Note that I only put "Threading.Thread.Sleep(50)" in there to slow down the execution of the loop. It will work just as well without it.

jazz__manAuthor Commented:
Ok, cheers Wayne.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.