Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ToolStripProgressBar Class
Collapse the table of content
Expand the table of content

ToolStripProgressBar Class

Note: This class is new in the .NET Framework version 2.0.

Represents a Windows progress bar control contained in a StatusStrip.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public class ToolStripProgressBar : ToolStripControlHost
public class ToolStripProgressBar extends ToolStripControlHost
public class ToolStripProgressBar extends ToolStripControlHost

A ToolStripProgressBar control visually indicates the progress of a lengthy operation. The ToolStripProgressBar control displays a bar that fills in from left to right with the system highlight color as an operation progresses.


The ToolStripProgressBar control can only be oriented horizontally.

The ToolStripProgressBar 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. Use the ToolStripProgressBar to notify 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 zero, and the Maximum property is typically set to a value indicating the completion of a task. For example, to display the progress properly 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. Because the bar displayed in the control is a collection of blocks, the value displayed by the ToolStripProgressBar only approximates the Value property's current value. Based on the size of the ToolStripProgressBar, the Value property determines when to display the next block.

There are a number of ways to modify the value displayed by the ToolStripProgressBar 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 by which to increment the Value property.

ToolStripProgressBar replaces the older ProgressBar control, which is nevertheless retained for backward compatibility.

The following code example demonstrates a ToolStripProgressBar that calculates a sequence of Fibonacci numbers.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.ComponentModel;

class FibonacciNumber : Form
	static void Main()
		Application.Run(new FibonacciNumber());

	private StatusStrip progressStatusStrip;
	private ToolStripProgressBar toolStripProgressBar;
	private NumericUpDown requestedCountControl;
	private Button goButton;
	private TextBox outputTextBox;
	private BackgroundWorker backgroundWorker;
	private ToolStripStatusLabel toolStripStatusLabel;
	private int requestedCount;

	public FibonacciNumber()
		Text = "Fibonacci";
		// Prepare the StatusStrip.
		progressStatusStrip = new StatusStrip();
		toolStripProgressBar = new ToolStripProgressBar();
		toolStripProgressBar.Enabled = false;
		toolStripStatusLabel = new ToolStripStatusLabel();

		FlowLayoutPanel flp = new FlowLayoutPanel();
		flp.Dock = DockStyle.Top;

		Label beforeLabel = new Label();
		beforeLabel.Text = "Calculate the first ";
		beforeLabel.AutoSize = true;
		requestedCountControl = new NumericUpDown();
		requestedCountControl.Maximum = 1000;
		requestedCountControl.Minimum = 1;
		requestedCountControl.Value = 100;
		Label afterLabel = new Label();
		afterLabel.Text = "Numbers in the Fibonacci sequence.";
		afterLabel.AutoSize = true;
		goButton = new Button();
		goButton.Text = "&Go";
		goButton.Click += new System.EventHandler(button1_Click);

		outputTextBox = new TextBox();
		outputTextBox.Multiline = true;
		outputTextBox.ReadOnly = true;
		outputTextBox.ScrollBars = ScrollBars.Vertical;
		outputTextBox.Dock = DockStyle.Fill;


		backgroundWorker = new BackgroundWorker();
		backgroundWorker.WorkerReportsProgress = true;
		backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
		backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
		backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

	private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
		// This method will run on a thread other than the UI thread.
		// Be sure not to manipulate any Windows Forms controls created
		// on the UI thread from this method.
		backgroundWorker.ReportProgress(0, "Working...");
		Decimal lastlast = 0;
		Decimal last = 1;
		Decimal current;
		if (requestedCount >= 1)
		{ AppendNumber(0); }
		if (requestedCount >= 2)
		{ AppendNumber(1); }
		for (int i = 2; i < requestedCount; ++i)
			// Calculate the number.
			checked { current = lastlast + last; }
			// Introduce some delay to simulate a more complicated calculation.
			backgroundWorker.ReportProgress((100 * i) / requestedCount, "Working...");
			// Get ready for the next iteration.
			lastlast = last;
			last = current;

		backgroundWorker.ReportProgress(100, "Complete!");

	private delegate void AppendNumberDelegate(Decimal number);
	private void AppendNumber(Decimal number)
		if (outputTextBox.InvokeRequired)
		{ outputTextBox.Invoke(new AppendNumberDelegate(AppendNumber), number); }
		{ outputTextBox.AppendText(number.ToString("N0") + Environment.NewLine); }
	private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
		toolStripProgressBar.Value = e.ProgressPercentage;
		toolStripStatusLabel.Text = e.UserState as String;

	private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		if (e.Error is OverflowException)
		{ outputTextBox.AppendText(Environment.NewLine + "**OVERFLOW ERROR, number is too large to be represented by the decimal data type**"); }
		toolStripProgressBar.Enabled = false;
		requestedCountControl.Enabled = true;
		goButton.Enabled = true;


	private void button1_Click(object sender, EventArgs e)
		goButton.Enabled = false;
		toolStripProgressBar.Enabled = true;
		requestedCount = (int)requestedCountControl.Value;
		requestedCountControl.Enabled = false;


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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft