Returns the size that text would take up if it was drawn.

 

   
Syntax
 
     

[Visual Basic]
Function TextArea(inText As String, inParams As String, ByRef outW As Integer, ByRef outH As Integer, ByRef outLH As Integer) As String

[C#]
string TextArea(string inText, string inParams, ref int outW, ref int outH, ref int outLH);

 

   
Params
 
     
Name   Description
inText The text to be drawn.
inParams A parameter string containing Override parameters, Positioning parameters and Transform parameters.
outW On return set to the width of the text.
outH On return set to the height of the text.
outLH On return set to the height of one line of text.
return The three values outW, outH and outLH in a comma delimited string.

 

   
Notes
 
     

This method takes the same arguments as the DrawText method. However it measures the area the text would cover rather than doing any drawing.

TextArea starts by extending a rectangle to the right until the width of the supplied rectangle has been reached. After this it extends the rectangle down, line by line until the end of the text.

 

   
See Also
 
     

Canvas DrawText function.
Canvas TextLength function.

 

   
Example
 
     

[Visual Basic]
Dim ca As New Canvas
Dim text, pars As String
Dim mywidth, myheight, mylineheight As Integer
text = "In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with..."
pars = "Rect=10,10,290,290"
ca.Color = System.Drawing.Color.Cyan
ca.Width = 300
ca.Height = 300
ca.TextFont = "Franklin Gothic, Verdana, Arial"
ca.TextSize = 18
ca.DrawText(text, pars)
ca.TextArea(text, pars, mywidth, myheight, mylineheight)
ca.DrawShape("rect", "Operation=draw Pos=10,10 Size=" + mywidth.ToString() + "," + myheight.ToString())
ca.DrawShape("rect", "Operation=draw Pos=10,10 Size=" + mywidth.ToString() + "," + mylineheight.ToString())
ca.SaveAs(Server.MapPath("textarea.jpg"), "Quality=high")

[C#]
Canvas ca = new Canvas();
int mywidth, myheight, mylineheight;
string text = "In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with...";
string pars = "Rect=10,10,290,290";
ca.Color = System.Drawing.Color.Cyan;
ca.Width = 300;
ca.Height = 300;
ca.TextFont = "Franklin Gothic, Verdana, Arial";
ca.TextSize = 18;
ca.DrawText(text, pars);
ca.TextArea(text, pars, out mywidth, out myheight, out mylineheight);
ca.DrawShape("rect", "Operation=draw Pos=10,10 Size=" + mywidth.ToString() + "," + myheight.ToString());
ca.DrawShape("rect", "Operation=draw Pos=10,10 Size=" + mywidth.ToString() + "," + mylineheight.ToString());
ca.SaveAs(Server.MapPath("textarea.jpg"), "Quality=high");

The code above draws out a short piece of text onto a canvas. After it has drawn it it measures the length of the text and draws a box round it and around the first line. The image that is saved is shown below.

textarea.jpg