tags:

views:

839

answers:

4

Hi all, i need to insert a progress bar between 2 forms ,i have a Main Form when i click a button to open a window i need wait before to load the last one window ('cos there are many picture to download on the last one Form) and i decide to use a Progress Bar to show the time remaining to open the Window requested. Now i don't know how implement in code this feature (it's the first time i use a Progress Bar) . Do you have any advice to help me how work out this feature? Thanks for your attention.

P.S .Sorry from my bad english

+2  A: 

Here is a simple example....

There are only three members of the ProgressBar class you should know about. The Maximum, the Minimum, and the Value properties.

You create a progress bar control using ProgressBar constructor.

this.progressBar1 = new System.WinForms.ProgressBar();

After creating instance of a progress bar you set the range of the progress bar by using Minimum and Maximum properties of the ProgressBar.

progressBar1.Maximum = 200; progressBar1.Manimum=0;

The Step property is used to set number of steps in a progress bar.

progressBar1.Step=20;

The Value property is used to set the current value of the status bar.

protected void displayProgress (object sender, System.EventArgs e)

{

if (progressBar1.Value >= 200 )

{

    progressBar1.Value = 0;

    return;
}

progressBar1.Value += 20;

}

northpole
+2  A: 

I'd recommend implementing the BackgroundWorker object in your Winforms application.

This will provide an easy multithreaded approach to doing something processing intensive without locking up your application. You can use this in conjunction with the ProgressBar, or you can even setup your own process indicator.

Dillie-O
+1  A: 

If you know how many pictures the new window will be downloading it is rather easy to implement the progress bar.

Just drop a progressbar somewhere on your form in the form-designer of Visual studio. Now you can use the progressbar in your code like the following:

MyProgressBar.Minimum = 0;
MyProgressBar.Maximum = TotalPicturesToDownload;

for (int i = 1; i<= TotalPicturesToDownload; i++)
{
//Do whatever necessary to download picture nr i
//....

//Update the progressBar
MyProgressBar.Increment(1);

}

Like already mentioned it is advisable to not do this in the UI thread but on a separate thread (use eg a BackGroundWorker) otherwise your form could be freezing up and making your progressbar not to update.

Mez