This article will teach you how you can show the progress bar in Windows applications, using C#.NET. So, for this application, first we will create a new Windows application and add a progress bar control.
Now, we will assign the maximum value to the progress bar control. This will help to show the progress.
After this control setting, we will add a backgroundWorker control.
Now, generate the DoWork and ProgressChanged event for the control backgroundWorker.


After this, we will add the code on DoWork event.
  1. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  2. {
  3. for (int i = 1; i <= 100; i++)
  4. {
  5. // Wait 50 milliseconds.
  6. Thread.Sleep(50);
  7. // Report progress.
  8. backgroundWorker1.ReportProgress(i);
  9. }
  10. }
Now, we will add the code for ProgressChanged.
  1. private void backgroundWorker1_ProgressChanged(object sender,
  2. ProgressChangedEventArgs e)
  3. {
  4. // Change the value of the ProgressBar
  5. progressBar1.Value = e.ProgressPercentage;
  6. // Set the text.
  7. this.Text = e.ProgressPercentage.ToString();
  8. }
Now, we will add the code to invoke the backgroundWorker.
  1. private void Form2_Load(object sender, System.EventArgs e)
  2. {
  3. backgroundWorker1.WorkerReportsProgress = true;
  4. backgroundWorker1.RunWorkerAsync();
  5. }
So, here is the complete code of what we have done.
  1. using System.ComponentModel;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4. namespace WindowsFormsApplication1
  5. {
  6. public partial class Form2 : Form
  7. {
  8. public Form2()
  9. {
  10. InitializeComponent();
  11. }
  12. private void Form2_Load(object sender, System.EventArgs e)
  13. {
  14. backgroundWorker1.WorkerReportsProgress = true;
  15. backgroundWorker1.RunWorkerAsync();
  16. }
  17. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  18. {
  19. for (int i = 1; i <= 100; i++)
  20. {
  21. // Wait 50 milliseconds.
  22. Thread.Sleep(50);
  23. // Report progress.
  24. backgroundWorker1.ReportProgress(i);
  25. }
  26. }
  27. private void backgroundWorker1_ProgressChanged(object sender,
  28. ProgressChangedEventArgs e)
  29. {
  30. // Change the value of the ProgressBar
  31. progressBar1.Value = e.ProgressPercentage;
  32. // Set the text.
  33. this.Text = "Progress: " + e.ProgressPercentage.ToString() + "%";
  34. }
  35. }
  36. }
Now, we are done. Run the application to check the output.