Windows Control: The Progress Bar



A progress bar is a control that displays (small) rectangles that are each filled with a color. These (small) rectangles are separate but adjacent each other so that, as they display, they produce a bar. To have the effect of a progress bar, not all these rectangles display at the same time. Instead, a numeric value specifies how many of these (small) rectangles can display at one time.


Creating a Progress Bar

To support progress bars, the .NET Framework provides the ProgressBar class, which is derived from the Control class. In the Toolbox, the progress bar is represented by the ProgressBar control. At design time, to get a progress bar, from the Common Controls section of the Toolbox, you can click the ProgressBar control and click the form (or another container).

To programmatically get a progress bar, declare a variable of type ProgressBar, use the new operator to allocate memory for it, and add it to the Controls property of its container. Here is an example:

using System;
using System.Drawing;
using System.Windows.Forms;

public class Exercise : System.Windows.Forms.Form
    ProgressBar progress;

    public Exercise()

    private void InitializeComponent()
        Text = "Progressive Studies";
        Size = new Size(242, 80);

        progress  = new ProgressBar ();


public class Program
    static int Main()
        System.Windows.Forms.Application.Run(new Exercise());
        return 0;

This would produce:

Progress Bar


Home Copyright © 2007 FunctionX, Inc. Next