Thread: progressBar

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    progressBar

    In this forloop I am reading 3 files that takes about 20 seconds.

    Now I have done a formula: (out / count) * 100 that will show progress.
    So for the first file wich will be (1 / 3) * 100 wich will have a value of 33.33
    the progressbar should be on 33.33 % but this is not happening ?
    It waits until all 3 files is read and then display 100 % directly.

    Any idéas why this is happening. 100 is the MaxValue for the progressBar1.
    (If I just put a number like for example 30 instead the progressBar1 will fill up to 30 %.)

    Code:
    int count = 3;
    
    for (int out = 1; out < (count + 1); out++)
    	{ 
    	        this->progressBar1->Value = (out / count) * 100;
            }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Change this seemed to solve the problem.

    Code:
    int out
    to
    double out

    So the progressbar is working correctly now.

    Another problem is occuring and that is on my Form I have a progressbar and a buttoncontrol.
    When I press the button the progressbar is starting out with this for-loop.

    Now if I press for example on the desktop with my cursor
    wich make the form "unactive" the progressbar stops at the position it is and never starts again.
    The whole form is "Not Responding" until the for-loop is ready.

    What does this depend on. How can it be possible to update the progressbar/Form for each looping. I dont really know the reason to this ?
    Last edited by Coding; 02-22-2008 at 08:41 PM.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I have googled around and think that I have to activate the Form for each looping but are not sure that this is the approach.
    The syntax I have seen is: Activated() but this is all I know if I am on the right track.

    I have tried this inside the loop but this did not work:
    Code:
    this->Activate();
    this->progressBar1->Value = (out / count) * 100;
    Last edited by Coding; 02-22-2008 at 10:08 PM.

  4. #4
    Registered User AloneInTheDark's Avatar
    Join Date
    Feb 2008
    Posts
    74
    Try putting a "Application.DoEvents();" inside your loop.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Assuming you're using .NET 2.0+, look into the BackgroundWorker component.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    The "Application:: DoEvents();" for .NET 2008 worked for this.
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. progressbar
    By munna_dude in forum C Programming
    Replies: 8
    Last Post: 06-21-2007, 06:17 AM
  2. ProgressBar
    By Leite33 in forum Windows Programming
    Replies: 1
    Last Post: 01-15-2007, 08:21 AM
  3. Refresh ProgressBar
    By Dimeslime in forum C# Programming
    Replies: 2
    Last Post: 10-22-2003, 02:47 PM
  4. Progressbar as Part of Statusbar :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-26-2002, 08:59 AM
  5. More PROGRESSBAR help!(SIMPLE!)
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2001, 03:39 PM