Jump to content

C# progress bar help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

I am new to progress bar, just need help, ok lets say this, i wish it was easy as:

public void loadingbar()

{

progressbar.increment(1);

}

 

public void loadingdata()

{

progressbar.maximum = 100;

blah blah add to list

foreach this and that blah blah //i know most of this doesnt work but bare with me its part of my //explanation

 

loadingbar();

}

so i wish it was that easy, let me explain now, is there way to have a progress bar keep track of the process that is happening within the method of loadingdata, such as start to finish, when the method starts, thats when the progress bar appears, and continues to increment by 1 until the last foreach whatever or anything within that method is done then the progress bar would show full bars and i could say in text... all done or something, any ideas on how to do that?

thanks

Edited by Roger, 03 April 2011 - 10:59 AM.
added code tags

Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#2
hampus.tagerud

hampus.tagerud

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Maybe you could use an int in a usual for loop? (not foreach)

like

public void loadingdata()

{

     for(int i = 1; i <= 100; i++)

           //Something happens here!!

     loadingbar();

}

or if you want to use the foreach

public void loadingdata()

{

     foreach(something something in somethings)

     {

           //Something happens here!!

           loadingbar();

     }

}

so you put the loadingbar void inside the loop...

I have no idea if you want to track a progress of an void without a loop

Edited by Roger, 03 April 2011 - 10:59 AM.
added code tags


#3
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
thanks for the reply,

i went ahead and just had my form appear, as showdialog method, and just show the progress1.style continue pretty much i guess you might say this is a work around, but i will look into what Hampus was saying, but i have another problem,
since my form1.showdialog appears, the other things that come after that, doesnt within the method, doesnt seem to run, it only stops at form1.showdialog.... how do i tell it to continue, now if i use show method, it works fine, but i want to use showdialog so they cant try and click out of the form, so any ideas, also form1 is with the progress bar, so if I can have the progressbar run while the method still continues that would be great, any ideas?

here is an example

public void method()

{

form1 form = new form1();

form.showdialog();

//doesnt continue after form.showdialog... why!!!???

method2();

method3();

}

thanks any help would be great.

Edited by Roger, 03 April 2011 - 10:59 AM.
added code tags

Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#4
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
I don't know what you are loading, therefore i can't give you a good example, but i can show you how the progressBar works:

You set the minimum and maximum:
progressBar1.Maximum = 100;
progressBar1.Minimum = 0;
Then, let's say you load your data in a for loop:
for (int i=0; i<=100; i++) {
      progressBar1.Value++;
}
Try it and see for yourself, then try to adapt it to your loading. Tell me if you need more help.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#5
hampus.tagerud

hampus.tagerud

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts

Siten0308 said:

thanks for the reply,

i went ahead and just had my form appear, as showdialog method, and just show the progress1.style continue pretty much i guess you might say this is a work around, but i will look into what Hampus was saying, but i have another problem,
since my form1.showdialog appears, the other things that come after that, doesnt within the method, doesnt seem to run, it only stops at form1.showdialog.... how do i tell it to continue, now if i use show method, it works fine, but i want to use showdialog so they cant try and click out of the form, so any ideas, also form1 is with the progress bar, so if I can have the progressbar run while the method still continues that would be great, any ideas?

here is an example

public void method()
{
form1 form = new form1();
form.showdialog();
//doesnt continue after form.showdialog... why!!!???
method2();
method3();
}

thanks any help would be great.

When you call the .showDialog method the void pauses until that dialog is closed, so whats written after the showdialog is going to happen, but not until you close the dialog.

Hope this helps!

#6
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
thanks for the replies, i figured that was the problem for the showdialog, however, is there a way to by pass the showdialog issue such as

form1.showdialog
continue;

or something like that?
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#7
hampus.tagerud

hampus.tagerud

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Not that I know of but it might be possible...

Maybe you can run the actions from the form?

#8
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
i tried that too, just now, sadly i couldnt get it to work, i tried for the main form, just loadingform.showdiaog(), but i am still trying to see if i can use anonymous method using the loadingform.show event, unless anyone else recommends anything else to try?

I will let you know the results very soon if the anonymous method works for my headache :(
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#9
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Nope anonymous failed, if i do loadingform.show(), the form freezes, but if i do showdialog(), it doesnt freeze but doesnt continue with the method... such a headache :( but it will be awesome to figure this out
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)