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

Posted on 2008-11-10
Last Modified: 2013-11-07

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.
Question by:jazz__man
    LVL 46

    Accepted Solution

    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

    LVL 2

    Author Closing Comment

    All I needed was these two lines..

    Superb!! Have a nice day.


    LVL 46

    Expert Comment

    by:Wayne Taylor (webtubbs)

    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.

    LVL 2

    Author Comment

    Ok, cheers Wayne.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now