Search code examples
c#progress-barwebservices-client

Using a progress bar in C#


I am currently getting the status of files getting sent to a webservice to be displayed in a richTextBox however for demonstration purposes I would prefer it to be shown as a progress bar.

so far my code is -

        richTextBox1.Text = richTextBox1.Text + action + "ok: " +  ok.ToString();
        richTextBox1.Text += "\r\n";
        richTextBox1.Text = richTextBox1.Text + "err: " + err.ToString();
        richTextBox1.Text = richTextBox1.Text + "\r\n";

This works fine but I really think a progress bar would look better, I have trieda couple of things i.e -

        progressBar1.Equals = action;

But this doesn't seem to work, any input is greatly appreciated.


Solution

  • To work with a progress bar you have to set a minimum of 2 values:

    The first value is Maximum and indicates the max value of your value bar (for example the total number of files to trasnfer)

    Then, every time you want to update the bar you have to set the Value properties that indicates the current position of the bar (for example the number of files you actually transferred)

    To be sure the bar receive a correct visual update in a form, you have to call Application.DoEvents() if you are doing your update in a loop