Skip to content

ProgressBar class ​

A ProgressBar is a horizontal or vertical bar that visually represents progress through a range. Three configurable axes shape the visual: Scrolling (segmented / smooth / marquee), State (Normal / Error / Paused, which tints the bar to match the OS theme), and Orientation (horizontal or vertical).

vb
Private Sub StartTask()
    ProgressBar1.Min = 0
    ProgressBar1.Max = ItemCount
    ProgressBar1.Step = 1
    ProgressBar1.Value = 0
End Sub

Private Sub OnItemDone()
    ProgressBar1.StepIt   ' advances by Step (1 here) and fires Change
End Sub

Private Sub OnTaskFailed()
    ProgressBar1.State = PrbStateError
End Sub

For indeterminate progress (e.g. waiting on a server response with no length information), use the marquee variant:

vb
ProgressBar1.Scrolling = PrbScrollingMarquee
ProgressBar1.MarqueeSpeed = 30       ' milliseconds per animation step
ProgressBar1.MarqueeAnimation = True ' start animating

The control inherits the non-focusable rect-dockable members from BaseControlNotFocusable2 --- size, position, Anchors, Dock, Appearance, MousePointer / MouseIcon, ToolTipText, DragMode / DragIcon, Drag, Refresh, ZOrder, CausesValidation, VisualStyles, hWnd, HelpContextID / WhatsThisHelpID.

Three axes of configuration ​

The visual is the cartesian product of three properties:

  • Scrolling --- Standard (the default, animated segmented bar), Smooth (a continuous block --- combine with SmoothReverse to allow the bar to decrease), or Marquee (an indeterminate animated stripe; control with MarqueeAnimation + MarqueeSpeed).
  • State --- Normal (theme-default color, typically green), Error (typically red), or Paused (typically yellow). The OS chooses the actual colors based on its current theme.
  • Orientation --- Horizontal or Vertical.

All three can be changed at run time; the underlying Win32 styles are re-applied without recreating the window.

Range, value, and stepping ​

Min and Max bracket the range. Value is the current position. Step is the amount StepIt advances the bar by, used to power the common loop pattern:

vb
ProgressBar1.Min = 0
ProgressBar1.Max = Items.Count
ProgressBar1.Step = 1
For Each item In Items
    DoWork item
    ProgressBar1.StepIt
Next

Each StepIt call increments Value by Step and fires the Change event.

Properties ​

BackColor ​

The background color drawn behind the progress bar segments. OLE_COLOR. Default: vbButtonFace. Applied via PBM_SETBKCOLOR.

BorderStyle ​

The control's border style. A ControlBorderStyleConstants member. Default: vbNoBorder.

ForeColor ​

The color of the progress bar segments themselves. OLE_COLOR. Default: vbHighlight. Applied via PBM_SETBARCOLOR.

INFO

The OS visual styles theme typically overrides this value in standard rendering. To see the assigned ForeColor at run time, disable visual styles by setting VisualStyles to False.

MarqueeAnimation ​

Whether the marquee animation is currently running. Boolean. Default: False. Only meaningful when Scrolling is PrbScrollingMarquee. Set to True to start, False to stop.

MarqueeSpeed ​

The marquee animation update interval, in milliseconds. Long. Default: 80.

Max ​

The upper bound of the range. Long. Default: 100. The combination of Min and Max is applied to the underlying control via PBM_SETRANGE32.

Min ​

The lower bound of the range. Long. Default: 0.

Orientation ​

The progress bar's orientation. A member of PrbOrientation. Default: PrbOrientationHorizontal.

Scrolling ​

The visual style of progress. A member of PrbScrolling. Default: PrbScrollingStandard.

SmoothReverse ​

Whether a smooth progress bar can decrease (when Value is set to a smaller number). Boolean. Default: False. Without this flag a smooth bar that has reached, say, 80% will not visibly decrease when Value is reduced --- it simply snaps back. Only meaningful when Scrolling is PrbScrollingSmooth.

State ​

The visual state of the bar. A member of PrbState. Default: PrbStateNormal. The OS uses the value to tint the bar --- PrbStateError typically renders red, PrbStatePaused typically renders yellow, PrbStateNormal uses the theme-default progress color (typically green).

Step ​

The amount StepIt advances Value by. Long. Default: 10.

Value ​

The current position in the range. Long. The default member. Reads and writes via PBM_GETPOS / PBM_SETPOS. Fires Change when the value is changed past the control's initialization phase.

Methods ​

StepIt ​

Advances Value by Step, wrapping to Min once Max is reached. Fires the Change event.

Syntax: object.StepIt

Events ​

Change ​

Raised when Value has changed --- either through direct assignment, through StepIt, or by code adjusting Step and re-applying.

Syntax: object_Change( )

Click, DblClick ​

Inherited mouse events.

DragDrop, DragOver ​

Inherited drag-drop events.

Initialize ​

Raised after the control's window has been created.

MouseDown, MouseMove, MouseUp ​

Inherited mouse events.

OLECompleteDrag, OLEDragDrop, OLEDragOver, OLEGiveFeedback, OLESetData, OLEStartDrag ​

Inherited OLE drag-and-drop events.

PrbOrientation ​

Determines the orientation of the progress bar. Declared on the ProgressBar class.

MemberValueDescription
PrbOrientationHorizontal0Horizontal bar; progress flows left-to-right.
PrbOrientationVertical1Vertical bar; progress flows bottom-to-top.

PrbScrolling ​

Determines how the progress bar animates as the value changes. Declared on the ProgressBar class.

MemberValueDescription
PrbScrollingStandard0Segmented bar with the classic discrete blocks animation.
PrbScrollingSmooth1Continuous block with no inter-segment gaps. Pair with SmoothReverse to allow the value to decrease visibly.
PrbScrollingMarquee2Indeterminate animated stripe. Control with MarqueeAnimation and MarqueeSpeed; the actual Value is irrelevant.

PrbState ​

Determines the color theme of the progress bar. Declared on the ProgressBar class.

MemberValueDescription
PrbStateNormal1Theme-default progress color (typically green).
PrbStateError2Error state (typically red).
PrbStatePaused3Paused state (typically yellow).

See Also ​

  • Slider -- when the user needs to set a value within a range, not just see progress
  • ControlTypeConstants -- where vbProgressBar lives

twinBASIC and LOGO copyright of "WaynePhillipsEA" author