Draw text on the canvas.
Syntax

[C#]

XRect DrawText(string inText, double inWidth, double inHeight, DrawOptions inOptions);
XRect DrawText(string inText, DrawOptions inOptions);
XRect DrawText(string inText, XPoint inPos, DrawOptions inOptions);
XRect DrawText(string inText, XRect inRect, DrawOptions inOptions);

[Visual Basic]

Function DrawText(inText As String, inWidth As Double, inHeight As Double, inOptions As DrawOptions) As XRect
Function DrawText(inText As String, inOptions As DrawOptions) As XRect
Function DrawText(inText As String, inPos As XPoint, inOptions As DrawOptions) As XRect
Function DrawText(inText As String, inRect As XRect, inOptions As DrawOptions) As XRect
Params
Name Description
inText The text to draw.
inWidth The text width.
inHeight The text height.
inOptions The draw options.
inPos The text position.
inRect The text rectangle.
return The drawn area.
Notes

The text is drawn within the rectangle specified by inRect or inSize. If no rectangle is specified the entire canvas is used as a rectangle. The text can also be positioned via the inRect top left property or via inPos.

The font, size, style and color are determined by DrawOptions.

If no position is specified the text rectangle will be aligned using the horizontal and vertical alignment properties of DrawOptions: HAlign and VAlign. The alignment of the text within its rectangle is determined by TextHAlign and TextVAlign.

Note that if you use characters outside the normal ASCII range (e.g. for Japanese or other Unicode) you must set the Language to Unicode.

If the Canvas has not been sized yet (both Height and Width are still zero), it will be auto-sized to the text rectangle, if one has been specified. If no rectangle has been specified, a rectangle suitable for drawing the text will be used.

See Also

DrawOptions

GetTextMetrics

Example

Here we draw some text on a Canvas.

[C#]Canvas canvas = new Canvas();
canvas.DrawText("Here is some text...", new DrawOptions(canvas));
canvas.SaveAs(Server.MapPath("Canvas_DrawText_95.png"));


[Visual Basic]Dim canvas As New Canvas()
canvas.DrawText("Here is some text...", New DrawOptions(canvas))
canvas.SaveAs(Server.MapPath("Canvas_DrawText_95.png"))



Canvas_DrawText_95.png