Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ProgressBar Class

Represents a Windows progress bar control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public class ProgressBar : Control

A ProgressBar control visually indicates the progress of a lengthy operation in one of three styles:

  • Segmented blocks that increase in steps from left to right.

  • A continuous bar that fills in from left to right.

  • A block that scrolls across a ProgressBar in a marquee fashion.

The Style property determines the style of ProgressBar that is displayed. Note that the ProgressBar control can only be oriented horizontally. For an example of how to create a vertically oriented ProgressBar, see the ProgressBarRenderer class. The ProgressBar control is typically used when an application performs tasks such as copying files or printing documents. Users of an application might consider an application unresponsive if there is no visual cue. By using the ProgressBar in your application, you alert the user that the application is performing a lengthy task and that the application is still responding.

The Maximum and Minimum properties define the range of values to represent the progress of a task. The Minimum property is typically set to a value of 0, and the Maximum property is typically set to a value indicating the completion of a task. For example, to properly display the progress when copying a group of files, the Maximum property could be set to the total number of files to be copied.

The Value property represents the progress that the application has made toward completing the operation. The value displayed by the ProgressBar only approximates the current value of the Value property. Based on the size of the ProgressBar, the Value property determines when to display the next block or increase the size of the bar.

There are a number of ways to modify the value displayed by the ProgressBar other than changing the Value property directly. You can use the Step property to specify a specific value to increment the Value property by, and then call the PerformStep method to 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.


ForeColor and BackColor changes for the ProgressBar will not be honored when visual styles are enabled on Windows XP Home Edition, Windows XP Professional, Windows Server 2003 and above.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: This class is sealed on the .NET Compact Framework.

The following code example uses a ProgressBar control to display the progress of a file copy operation. The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of files to copy. The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a file is copied. This example requires that you have a ProgressBar control created called pBar1 that is created within a Form and that there is a method created called CopyFile (that returns a Boolean value indicating the file copy operation was completed successfully) that performs the file copy operation. The code also requires that an array of strings containing the files to copy is created and passed to the CopyWithProgress method defined in the example and that the method is called from another method or event in the Form.

		private void CopyWithProgress(string[] filenames)
			// Display the ProgressBar control.
			pBar1.Visible = true;
			// Set Minimum to 1 to represent the first file being copied.
			pBar1.Minimum = 1;
			// Set Maximum to the total number of files to copy.
			pBar1.Maximum = filenames.Length;
			// Set the initial value of the ProgressBar.
			pBar1.Value = 1;
			// Set the Step property to a value of 1 to represent each file being copied.
			pBar1.Step = 1;
			// Loop through all files to copy. 
			for (int x = 1; x <= filenames.Length; x++)
				// Copy the file and increment the ProgressBar if successful. 
				if(CopyFile(filenames[x-1]) == true)
					// Perform the increment on the ProgressBar.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

© 2015 Microsoft