WebGraphics.TextAlignment

From Xojo Documentation

Property (As TextAlignments )
aWebGraphics.TextAlignment = newTextAlignmentsValue
or
TextAlignmentsValue = aWebGraphics.TextAlignment

Supported for all project types and targets.

Sets the text alignment of text created with DrawText.

Examples

This code centers the text in the drawing area:

Var txt As String = "Hello World"
Var y As Integer = 100
Var alignX As Integer = g.Width / 2
g.TextAlignment = TextAlignments.Center
g.DrawText(txt, alignX, y)

Show left-aligned, right-aligned and centered text, both within a Rect and within the entire Canvas. Be sue the Canvas is locked to all page edges so that it is large enough:

g.DrawRectangle(0, 10, 200, 100)

g.TextAlignment = TextAlignments.Left
g.DrawText("Left-aligned (Box)", 5, 20) ' in box
g.DrawText("Left-aligned (Canvas)", 5, 200, g.Width) ' in canvas

g.TextAlignment = TextAlignments.Right
g.DrawText("Right-aligned (Box)", 195, 40) ' in box
g.DrawText("Right-aligned (Canvas)", g.Width, 250, g.Width) ' in canvas

g.TextAlignment = TextAlignments.Center
g.DrawText("Centered (Box)", 100, 60) ' in box
g.DrawText("Centered (Canvas)", g.Width / 2, 300, g.Width) ' in canvas

This code splits a number into two parts so you can do decimal alignment:

Var c As Currency = 15.32
Var cText As String = c.ToString
Var parts() As String = cText.Split(".")
Var y As Integer = 100
Var alignX As Integer = g.Width/2
g.TextAlignment = WebGraphics.TextAlignmentRight
g.DrawText(parts(0) + ".", alignX, y)
g.TextAlignment = WebGraphics.TextAlignmentLeft
g.DrawText(parts(1), alignX, y)

See Also

TextAlignments enumeration.