Share via


How to: Program the Progress Bar Region of the Status Bar

The Progress Bar region of the Visual Studio status bar displays the incremental progress of quick operations, for example, saving a file to disk.

To use the Progress Bar region of the Visual Studio status bar

  1. Obtain an instance of the IVsStatusbar interface, which is made available through the SVsStatusbar service.

  2. Initialize the progress bar to starting values by calling the Progress method.

  3. Update the progress bar as your operation proceeds by using the Progress method to set new values.

Example

This example demonstrates how to initialize and update the progress bar.

Private Sub ProgressBarExample()
    Dim statusBar As IVsStatusbar = DirectCast(GetService(GetType(SVsStatusbar)), IVsStatusbar)
    Dim cookie As UInteger = 0
    Dim label As String = "Progress bar label..." 

    ' Initialize the progress bar. 
    statusBar.Progress(cookie, 1, "", 0, 0)

    Dim i As UInteger = 0, total As UInteger = 100
    While i <= total
        ' Display incremental progress. 
        statusBar.Progress(cookie, 1, label, i, total)
        System.Threading.Thread.Sleep(1)
        i += 1
    End While 

    ' Clear the progress bar. 
    statusBar.Progress(cookie, 0, "", 0, 0)
End Sub
void ProgressBarExample()
{
    IVsStatusbar statusBar =
        (IVsStatusbar)GetService(typeof(SVsStatusbar));
    uint cookie = 0;
    string label = "Progress bar label...";

    // Initialize the progress bar.
    statusBar.Progress(ref cookie, 1, "", 0, 0);

    for (uint i = 0, total = 100; i <= total; i++)
    {
        // Display incremental progress.
        statusBar.Progress(ref cookie, 1, label, i, total);
        System.Threading.Thread.Sleep(1);
    }

    // Clear the progress bar.
    statusBar.Progress(ref cookie, 0, "", 0, 0);
}

In the example, the code:

  • Obtains an instance of the IVsStatusbar interface from the SVsStatusbar service.

  • Initializes the progress bar to given starting values by calling the Progress method.

  • Simulates an operation by iterating through a for loop and updating the progress bar values by using the Progress method.

  • Clears the progress bar by using the Clear method.

See Also

Tasks

How to: Read from and Write to the Feedback Region of the Status Bar

How to: Use the Animation Region of the Status Bar

How to: Program the Designer Region of the Status Bar

Other Resources

Status Bar