Class

TextShape


Description

Draws a text string in a vector graphics environment.

Enumerations

TextShape.Alignment

Alignment

Used to set the HorizontalAlignment and VerticalAlignment properties. (Left, Top, Center, Baseline, Right, Bottom)

Enum

Value

Left

0

Top

1

Center

2

Baseline

3

Right

4

Bottom

5

Property descriptions


TextShape.Bold

Bold As Boolean

If True, applies the bold style to the text.

On macOS, apps can only display font styles that are available. You cannot force a font to display in bold or italic if it does not have bold or italic variations available. In this situation, the Bold property will not affect the font.

This code sets the text to Bold:

Var s As New TextShape
s.Text = "Hello World"
s.Bold = True
g.DrawObject(s)

TextShape.FillColor

FillColor As Color

The color of the interior of the shape.


TextShape.FillOpacity

FillOpacity As Double

The opacity of the interior, from 0 (completely transparent) to 100 (opaque).

This example sets the Fill to 10% opacity.

Var a As New TextShape
a.Text = "Hello world!"
a.FontSize = 24
a.FillOpacity = 10
a.FillColor = Color.Red
g.DrawObject(a)

TextShape.FontName

FontName As String

Name of the font used to display the text.

You can enter any font that is installed on the computer or the names of the two metafonts, "System" and "SmallSystem".

The System font is the font used by the system software as its default font. Different operating systems use different default fonts. If the system software supports both a large and small System font, you can also specify the "SmallSystem" font as your TextFont.

On macOS, "SmallSystem" specifies the OS's smaller system font and may make the control smaller in size as well. On Windows and Linux, "SmallSystem" is the same as "System".

This code sets the FontName property.

Me.FontName = "Helvetica"

TextShape.FontSize

FontSize As Double

Point size of the font used to display the text.

If you enter zero as the FontSize, your app will use the font size that works best for the platform on which it is running.

This code sets the font size to 16 points.

Me.FontSize = 16

TextShape.FontUnit

FontUnit As FontUnits

The units in which the FontSize is measured. Use FontUnits rather than the numeric values in code.

Me.FontUnit = FontUnits.Point

TextShape.HorizontalAlignment

HorizontalAlignment As Alignment

Sets the horizontal alignment of the TextShape.

The choices are: Left, Center, or Right. The default is Center. The alignment is relative to the Object2D.X property.

This example aligns the TextShape to the left.

Var ts As New TextShape
ts.X = 20
ts.Text = "Hello World"
ts.HorizontalAlignment = TextShape.Alignment.Left

TextShape.Italic

Italic As Boolean

If True, applies the italic style to the text.

Mac apps can only display font styles that are available. You cannot force a font to display in bold or italic if it does not have bold or italic variations available. In this situation, the Italic property will not affect the font.

The following sets the Italic property for the control.

Me.Italic = True

TextShape.Rotation

Rotation As Double

Clockwise rotation, in radians, around the X, Y point. Only set the rotation after you have drawn all your objects.

This code rotates the text 0.9 radians.

Var a As New TextShape
a.Text = "Hello World!"
a.Rotation = 0.90
g.DrawObject(a)

TextShape.Scale

Scale As Double

The scaling factor relative to the object's original size.

The following code rescales the arc by a factor of 5.

Var a As New TextShape
a.Text = "Hello World!"
a.Scale = 5
g.DrawObject(a)

TextShape.Text

Text As String

The text to draw.

The text can be only one text style (font, font size, style) specified by the other TextShape properties. Use the FillColor property to change the color of the text. Use a carriage return between text to display with multiple lines. The default text is an empty string.


TextShape.Underline

Underline As Boolean

If True, applies the underline style to the text.

This code underlines the control's text.

Me.Underline = True

TextShape.VerticalAlignment

VerticalAlignment As Alignment

Sets the vertical alignment of the TextShape.

The choices are: Top, Baseline, or Bottom. The default is Baseline. The alignment is relative to the Object2D.X and Y properties.

This code aligns the TextShape to the top:

Var ts As New TextShape
ts.X = 20
ts.Text = "Hello World"
ts.VerticalAlignment = TextShape.Alignment.Top

TextShape.X

X As Double

The horizontal position of the center or main anchor point.

This example sets the horizontal position to 100 pixels from the left of the containing Canvas.

Var a As New TextShape
a.Text = "Hello World!"
a.X = 100
g.DrawObject(a)

TextShape.Y

Y As Double

The vertical position of the center or main anchor point.

Notes

The X,Y properties specify the center of the text baseline. Text that contain line breaks are not supported. TextShapes can be rotated, but doing so is memory intensive, especially for large strings.

Although they will appear in auto-complete and compile, the Border, BorderColor and BorderWidth properties do not do anything with StringShape.

Use the FillColor property to change the color of the text.

Sample code

This example draws text rotated 90 degrees. Put it in the Paint event handler of a Canvas:

Var t As New TextShape
t.Text = "Hello World"
t.FontName = "Helvetica"
t.Bold = True
t.Rotation = 3.14159 / 2 ' (radians, 90 degrees = pi/2)
t.Y = 100
g.DrawObject(t)

This example aligns the TextShape to the left.

Var t As New TextShape
t.X = 20
t.Y = 20
t.Text = "Hello World"
t.HorizontalAlignment = TextShape.Alignment.Left
g.DrawObject(t)

Compatibility

Desktop and web project types on all supported operating systems.