Retrieve information for drawing text on a Canvas.
Syntax

[C#]

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

[Visual Basic]

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

Call this method before drawing text if you need text information such as how much space the text is going to take, the line height and so forth.

See Also

DrawOptions

XText

DrawText

Example

Here we draw some text and a box around it.

[C#]Canvas canvas = new Canvas();
DrawOptions drawOpts = new DrawOptions();
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Draw;
XText text = canvas.GetTextMetrics("Here is some text...", drawOpts);
canvas.DrawText(text.Text, drawOpts);
canvas.DrawRect(new XRect(0, 0, text.TextWidth, text.LineHeight), drawOpts);
canvas.SaveAs(Server.MapPath("Canvas_GetTextInfo_94.png"));


[Visual Basic]Dim canvas As New Canvas()
Dim drawOpts As New DrawOptions()
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Draw
Dim text As XText = canvas.GetTextMetrics("Here is some text...", drawOpts)
canvas.DrawText(text.Text, drawOpts)
canvas.DrawRect(New XRect(0, 0, text.TextWidth, text.LineHeight), drawOpts)
canvas.SaveAs(Server.MapPath("Canvas_GetTextInfo_94.png"))



Canvas_GetTextInfo_94.png