Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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
4
Medium Priority
?
275 Views
Last Modified: 2013-11-07
Hi

On my vb.net 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.
0
Comment
Question by:jazz__man
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 22920950
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.

Regards,

Wayne
        For i As Integer = 1 To 100
            ProgressBar1.Value += 1
            Label1.Text = ProgressBar1.Value & "%"
            Threading.Thread.Sleep(50)
            Application.DoEvents()
        Next

Open in new window

0
 
LVL 2

Author Closing Comment

by:jazz__man
ID: 31515004
All I needed was these two lines..
Threading.Thread.Sleep(50)
Application.DoEvents()

Superb!! Have a nice day.

Cheers

Paul
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22921119
Paul,

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.

Wayne
0
 
LVL 2

Author Comment

by:jazz__man
ID: 22921162
Ok, cheers Wayne.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

577 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