Partilhar via


ProgressBar Control Overview (Windows Forms)

NoteImportant

The ToolStripProgressBar control replaces and adds functionality to the ProgressBar control; however, the ProgressBar control is retained for both backward compatibility and future use, if you choose.

The Windows Forms ProgressBar control indicates the progress of a process by displaying an appropriate number of rectangles arranged in a horizontal bar. When the process is complete, the bar is filled. Progress bars are commonly used to give the user an idea of how long to wait for a process to complete; for instance, when a large file is being loaded.

NoteNote

The ProgressBar control can only be oriented horizontally on the form.

Key Properties and Methods

The key properties of the ProgressBar control are Value, Minimum, and Maximum. The Minimum and Maximum properties set the maximum and minimum values the progress bar can display. The Value property represents the progress that has been made toward completing the operation. Because the bar displayed in the control is composed of blocks, the value displayed by the ProgressBar control only approximates the Value property's current value. Based on the size of the ProgressBar control, the Value property determines when to display the next block.

The most common way to update the current progress value is to write code to set the Value property. In the example of loading a large file, you might set the maximum to the size of the file in kilobytes. For example, if the Maximum property is set to 100, the Minimum property is set to 10, and the Value property is set to 50, 5 rectangles will be displayed. This is half of the number that can be displayed.

However, there are other ways to modify the value displayed by the ProgressBar control, aside from setting the Value property directly. The Step property can be used to specify a value to increment the Value property by. Then, calling the PerformStep method will increment the value. To vary the increment value, you can use the Increment method and specify a value with which to increment the Value property.

Another control that graphically informs the user about a current action is the StatusBar control.

NoteImportant

The StatusStrip and ToolStripStatusLabel controls replace and add functionality to the StatusBar and StatusBarPanel controls; however, the StatusBar and StatusBarPanel controls are retained for both backward compatibility and future use, if you choose.

See Also

Reference

ProgressBar

Other Resources

ProgressBar Control (Windows Forms)