Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a progress bar but it not refreshing though I use refresh function.


C#
if (progressBar.Value == 100)
     {
        progressBar.Value = 0;
        lblProgressPercentage.Text = string.Empty;
     }



C#
 if (ofd.ShowDialog() != DialogResult.Cancel)
    {
        int singleBlock = 100 / ofd.FileNames.Count();

        for (int i = 0; i < ofd.FileNames.Count(); i++)
        {
            ----------------------
                Statements
            ----------------------
        }
progressBar.Value += singleBlock;
                    lblProgressPercentage.Text = progressBar.Value.ToString() + "% Processed";

                    int percent = (int)(((double)progressBar.Value / (double)progressBar.Maximum) * 100);
                    progressBar.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar.Width / 2 - 10, progressBar.Height / 2 - 7));
                    progressBar.Refresh();
                    System.Threading.Thread.Sleep(2000);
}



Whenever do this the progress bar not filling to corresponding value.

It works only if the statement exits.
Even label is not get updated.


How to solve this.
Posted

1 solution

You can try with this approach[^].

A practical example here[^].

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900