Visual Basic Concepts

Visual Studio 6.0

Using the ProgressBar Control

A ProgressBar control allows you to graphically represent the progress of a transaction. The control consists of a frame that is filled as the transaction occurs. The Value property determines how much of the control has been filled. The Min and Max properties set the limits of the control.

Use the ProgressBar whenever an operation will take more than a few seconds to complete. You must also know how long the process will take by using a known end point and setting it as the Max property of the control.

Tip   Giving the user visual feedback on how much time remains on a lengthy operation gives the perception of improved performance.

Possible Uses

  • To inform the user of progress as a file transfer occurs over a network.

  • To reflect the state of a process that takes more than a few seconds.

  • To inform the user of progress as a complex algorithm is being calculated.

Use the Value Property With the Min and Max Properties to Show Progress

To show progress in an operation, the Value property is continually incremented until a maximum — defined by the Max property — is reached. Thus the number of chunks displayed by the controls is always a ratio of the Value property to the Min and Max properties. For example, if the Min property is set to 1, and the Max property is set to 100, a Value property of 50 will cause the control to display 50 percent of the chunks, as shown:

Set the Max Property to a Known Limit

To program the ProgressBar, you must have a limit to which the Value property will climb. For example, if you are performing downloading a file, and your application can determine how large the files is in kilobytes, you can set the Max property to that number. As the file is downloaded, your application must also have some way of determining how many kilobytes have been downloaded; set the Value property to that number.

In cases where a Max property can't be determined in advance, you may want to use the Animation control to continuously show an animation until a Stop method is invoked in a terminate event.

For More Information   For information on using the Animation control, see "Using the Animation Control."

Hide the ProgressBar with the Visible Property

A progress bar usually doesn't appear until an operation has begun, and disappears again after the operation ends. Set the Visible property to True to show the control at the start of an operation, and reset the property to False to hide the control when the operation finishes.