GdPicture.NET Reference Guide
MeasureTextBox Method (GdPictureImaging)
Example 





GdPicture14 Namespace > GdPictureImaging Class : MeasureTextBox Method
GdPicture Image Identifier.
Text to draw.
Specifies/Receives the x-coordinate of the upper-left corner of the text box.
Specifies/Receives the y-coordinate of the upper-left corner of the text box.
Specifies/Receives the width, in pixels, of the text box.
Specifies/Receives the height, in pixels, of the text box.
The font size in units specified by the FontSetUnit() method.
A member of the TextAlign enumeration.
A member of the FontStyle enumeration.
The name of the font. IE: "Arial".
Set to True to apply the Antialiasing algorithm else False.
Receives the number of characters that actually fit into the layout rectangle.
Receives the number of lines that fit into the layout rectangle.
Measures the specified string when drawn with the specified Font and the specified alignment.
Syntax
'Declaration
 
Public Function MeasureTextBox( _
   ByVal ImageID As Integer, _
   ByVal Text As String, _
   ByRef Left As Integer, _
   ByRef Top As Integer, _
   ByRef Width As Integer, _
   ByRef Height As Integer, _
   ByVal FontSize As Single, _
   ByVal Alignment As TextAlignment, _
   ByVal FontStyle As FontStyle, _
   ByVal FontName As String, _
   ByVal AntiAlias As Boolean, _
   ByRef CharactersFitted As Integer, _
   ByRef LinesFilled As Integer _
) As GdPictureStatus

Parameters

ImageID
GdPicture Image Identifier.
Text
Text to draw.
Left
Specifies/Receives the x-coordinate of the upper-left corner of the text box.
Top
Specifies/Receives the y-coordinate of the upper-left corner of the text box.
Width
Specifies/Receives the width, in pixels, of the text box.
Height
Specifies/Receives the height, in pixels, of the text box.
FontSize
The font size in units specified by the FontSetUnit() method.
Alignment
A member of the TextAlign enumeration.
FontStyle
A member of the FontStyle enumeration.
FontName
The name of the font. IE: "Arial".
AntiAlias
Set to True to apply the Antialiasing algorithm else False.
CharactersFitted
Receives the number of characters that actually fit into the layout rectangle.
LinesFilled
Receives the number of lines that fit into the layout rectangle.

Return Value

Example
Drawing a text box on the image and highlight the text.
GdPictureImaging imaging = new GdPictureImaging();
string text = "Quod cum ita sit, paucae domus studiorum seriis cultibus antea celebratae nunc ludibriis ignaviae torpentis exundant, vocali sonu, perflabili tinnitu fidium resultantes. denique pro philosopho cantor et in locum oratoris doctor artium ludicrarum accitur et bybliothecis sepulcrorum ritu in perpetuum clausis organa fabricantur hydraulica, et lyrae ad speciem carpentorum ingentes tibiaeque et histrionici gestus instrumenta non levia.";
int pageWidth = 2480;
int pageHeight = 3508;
int left = 50, top = 50, outLeft = 50, outTop = 50;
int width = pageWidth - 100, outWidth = pageWidth - 100;
int height = pageHeight - 100, outHeight = pageHeight - 100;
int charsFitted = 0, linesFilled = 0;
int fontSize = 30;
bool antiAlias = true;
TextAlignment align = TextAlignment.TextAlignmentCenter;
int imgId = imaging.CreateNewGdPictureImage(pageWidth, pageHeight, System.Drawing.Imaging.PixelFormat.Format1bppIndexed, Color.White);
//measure the box surrounding the text.
GdPictureStatus status = imaging.MeasureTextBox(imgId, text, ref outLeft, ref outTop, ref outWidth, ref outHeight, fontSize, align, GdPicture14.FontStyle.FontStyleRegular, "Arial", antiAlias, ref charsFitted, ref linesFilled);
//draw a filled rectangle beneath the text to hightlight the text.
imaging.DrawFilledRectangle(imgId, outLeft, outTop, outWidth, outHeight, Color.Aqua, antiAlias);
//draw the text box with the box.
imaging.DrawTextBox(imgId, text, left, top, width, height, fontSize, align, GdPicture14.FontStyle.FontStyleRegular, Color.Black, "Arial", true, antiAlias);
imaging.SaveAsBMP(imgId, "test.bmp");
imaging.ReleaseGdPictureImage(imgId);
See Also

Reference

GdPictureImaging Class
GdPictureImaging Members