TextRendering class

Aggregates everything needed to draw a piece of text inside a control: the font, the padding, the fill that supplies the text colour, an optional array of outlines, the alignment within the available area, and the overflow behaviour. Reached as <state>.TextRendering, WaynesLabel.TextRendering, and CellRenderingOptions.TextRendering.

A newly-constructed TextRendering pre-sets its Fill to solid black so that text is immediately visible.

With lblTitle.TextRendering
    .Font.Size = 18
    .Font.Weight = tbBold
    .Alignment = tbAlignMiddleCenter
    .Fill.ColorPoints.SetSolidColor vbWhite
End With

Fill can hold a gradient just as well as a solid colour, so glyphs themselves can be painted with a top-to-bottom or corner-to-corner colour transition. Outlines is an array of Border elements stroked around the glyphs — a single thin black outline gives a “stickered” look; layering several outlines with different StrokeSize values produces a glow or drop-shadow:

With lblBanner.TextRendering
    .Font.Size = 32
    .Font.Weight = tbBold
    .Alignment = tbAlignMiddleCenter
    .Fill.SetSimplePattern vbWhite, &HCCCCFF, _
            Pattern:=tbGradientNorthToSouth
    Dim outline(0 To 0) As Border
    Set outline(0) = New Border
    outline(0).StrokeSize = 2
    outline(0).Fill.ColorPoints.SetSolidColor vbBlack
    .Outlines = outline
End With

Set OverflowMode to tbShrinkToFit to scale the glyphs down rather than truncating with an ellipsis when the text is too long for the available width — useful on fixed-width labels whose caption is set at runtime from data of unpredictable length.

Properties

Alignment

How the text is positioned horizontally and vertically within the available area (after Padding is applied). A member of TextAlignment. Default: tbAlignMiddleCenter.

Fill

The Fill that supplies the text colour or gradient. Pre-set to a solid black fill on construction.

Font

The FontStyle sub-object that gives the font size, weight, italic / underline / strikeout flags.

OverflowMode

How text longer than the available width is truncated. A member of TextOverflowMode. Default: tbAppendEllipsis.

Outlines

An array of Border elements describing one or more outlines that are stroked around the rendered glyphs. Read-write; an uninitialised array means no outline.

Padding

The Padding sub-object holding per-side padding inserted around the text inside its bounding rectangle. The Alignment is applied to the padded region.

Events

OnChanged

Raised when Alignment or OverflowMode is assigned, when Outlines is replaced or any of its elements raises OnChanged, or when Font, Padding, or Fill raise their own OnChanged.

FontStyle class

The font metrics that drive how TextRendering lays out text. Reached as TextRendering.Font.

Italic

When True, glyphs are rendered with italic styling. Boolean. Default: False.

Size

The font size in typographic points. PointSize. Default: 12.

Strikeout

When True, a horizontal line is drawn through the middle of each glyph. Boolean. Default: False.

Underline

When True, an underline is drawn beneath each glyph. Boolean. Default: False.

Weight

The font weight on the OpenType wght scale. A member of FontWeight. Default: tbNormal.

OnChanged

Raised when any of the five font-style fields is assigned. The parent TextRendering listens for this event and re-raises its own.