FormatText
The FormatText method writes a formatted character string at the specified location, using the currently created font.
FormatText
iLeft,iTop,iRight,iBottom,sText,iFlags[,bCalculateOnly]
Parameters
-
iLeft
-
[in] Specifies horizontal position of the left-hand side of text rectangle.
-
iTop
-
[in] Specifies vertical position of the top side of text rectangle.
-
iRight
-
[in/out] Specifies horizontal position of the right-hand side of text rectangle if bCalculateOnly parameter is not present or equal False.
If bCalculateOnly is present then the method can extend it.
-
iBottom
-
[in/out] Specifies vertical position of the bottom side of text rectangle if bCalculateOnly parameter is not present or equal False.
If bCalculateOnly is present then the method can extend it.
-
sText
-
Text string to be drawn.
-
iFlags
-
Contains combination of flags specifying how to format text. The flags are combined using bitwise Or operator.
The FormatText accepts the following flags:
| Parameter | Value | Description |
| ftLeft | 0 | Aligns text to the left |
| ftTop | 0 | Justifies the text to the top of the rectangle |
| ftCenter | 1 | Centers text horizontally in the rectangle |
| ftRight | 2 | Aligns text to the right |
| ftVCenter | 4 | Centers text vertically. Use this only in conjuction with ftSingleLine. |
| ftBottom | 8 | Justifies the text to the bottom of the rectangle. Use this only in conjuction with ftSingleLine |
| ftWordBreak | 16 | Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-line feed sequence also breaks the line. |
| ftSingleLine | 32 | Displays text on a single line only. Carriage returns and line feeds do not break the line. |
-
bCalculateOnly
-
Optional. If set to True then the TextOut method only calculates iRight and iBottom parameters of text rectangle, without
actually drawing the text. If text has to be drawn in one string (the ftSingleLine flag is set) then both iRight and iBottom parameters will be changed. If text
should be drawn in two or more strings then only iBottom pararameter will be changed.
Default value is False.
Remarks
If the bCalculateOnly parameter is not specified (or set to False) and text does not fit in the specified
rectangle then text will be truncated.
Example
This example draws right-aligned text.
View result
<%
Response.ContentType = "image/jpeg"
Dim g,ileft,iright,itop,ibottom
Dim eol,txt
eol = Chr(13) & Chr(10)
txt = "Text can be multiline:" & eol &_
"You can separate lines using standard EOL symbols pair (13,10). " &_
"Long lines will be broken."
Set g = CreateObject("shotgraph.image")
g.CreateImage 320,240,8
g.SetColor 0,255,255,255
g.SetBgColor 0
g.FillRect 0,0,320,240
g.SetColor 1,0,0,0
g.SetTextColor 1
g.CreateFont "Arial",0,32,0,True,False,False,False
g.FormatText 10,10,300,200,txt,16 or 2
Response.BinaryWrite g.JpegImage(90,0,"")
%>