Wednesday, April 11, 2012

Progress Bar control in C# (Windows Forms)

Author : Prakash Pradeep Gopu
A progress bar is a control that an application can use to indicate the progress of a lengthy operation such as calculating a complex result, downloading a large file from the Web etc.
ProgressBar controls are used whenever an operation takes more than a short period of time. The Maximum and Minimum properties define the range of values to represent the progress of a task.
Minimum : Sets the lower value for the range of valid values for progress.
Maximum : Sets the upper value for the range of valid values for progress.
Value   : This property obtains or sets the current level of progress.

By default maximum value will be 100 and minimum value will be 0. As the task proceeds, the Progress Bar fills in from the left to the right. To delay the program briefly so that you can view changes in the progress bar clearly.

The Following c# program shows the simple operation of progress bar.
1)Create  form in the windows application
2)Drag the Progress bar control on to your form and place button on to the same form.
3)Under the button click copy the following code.

private void button1_Click(object sender, EventArgs e)
        {
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 200;
            int i;
            for(i = 0; i <= 200; i++)
            {
               
                progressBar1.Value = i;
            }
        }

Output :


1 comment: