Article ID: 147809 - View products that this article applies to.
This article was previously published under Q147809
This article has been archived. It is offered "as is" and will no longer be updated.
Many applications use a status bar to display the progress of an installation or other lengthy process. Often the percent completed is printed in the middle of the bar and it changes color as the status bar passes over it. This article illustrates how to achieve this effect using Visual Basic for Windows. As a note, the professional and enterprise edition contain a progress bar control that could be used instead. For Win16 applications, the sample calldlls in vb\samples\calldlls uses shape controls to achieve the same effect.
The simplest way to specify the range of the status bar is to determine what the zero-based range will be and specify that value as the ScaleWidth of the horizontal scroll bar. Then you don't have to scale the data for each new sample.
Changing the color of the percentage displayed within the picture box is done by specifying the DrawMode as Not XOR Pen with a compatible background. When the bar is drawn, an exclusive OR is performed on each pixel. If the pixel is red, it is made white and vice versa. The text must be placed first because Print does not support DrawMode. The following program demonstrates how to display a red status bar with a red or white text message centered in it. Colors other than red are specified by changing the ForeColor property of the Picture Box Control.
Article ID: 147809 - Last Review: February 24, 2014 - Revision: 2.2