This is a C# Program to create a progress bar control.
This C# Program Creates a Progress Bar Control.
Here ProgressBar indicates visually the progress of an operation. It is best used on a long-running computation or task.
Here is source code of the C# Program to Create a Progress Bar Control. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Create a Progress Bar Control */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ProgressBar { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for (int i = 1; i <= 100; i++) { System.Threading.Thread.Sleep(100); backgroundWorker1.ReportProgress(i); } } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; this.Text = e.ProgressPercentage.ToString(); } private void Form1_Load(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } } }
This C# program is used to create a progress bar control. A Progress Bar control is used to represent the progress of a lengthy operation that takes time where a user must wait for the operation to be finished.
The Thread.Sleep() function is used to suspend the current thread for the specified number of milliseconds. In progress changed method assigns the value to Progress Bar using ‘ProgressPercentage’ which is used to get the task progress percentage.
Then RunWorkerAsync() function is used to start execution of a background operation. Here Progress Bar indicates visually the progress of an operation. It is best used on a long-running computation or task.
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy C# Books
- Buy MCA Books
- Buy Computer Science Books
- Practice MCA MCQs
- Apply for C# Internship