Control Reference > VSPrinter Control > VSPrinter Properties > Text Property (VSPrinter) |
Renders a string on the page at the current cursor position.
[form!]VSPrinter.Text = value As String
This property renders text on the page, at the current cursor position (determined by the CurrentX and CurrentY properties).
It is similar to the Paragraph property, except it does not terminate the string with a new line. Instead, it leaves the cursor at the point where the text stopped, allowing you to print a paragraph in pieces. This is the most efficient way to generate paragraphs with mixed fonts and colors.
For example, the following code prints VB source files. The code prints function names in bold red letters, and the remaining text in regular black characters:
Sub PrintVBFile(FileName as String)
Dim ln$, subname$, subargs$
Open FileName For Input As #1
With vp
.StartDoc
While Not EOF (1)
Line Input #1, ln
If Left(ln, 3) = "Sub" Then ' print function header
ln = Mid(ln, 4)
subname = Left(ln, Instr (ln, " "))
subargs = Mid(ln, Instr (ln, " "))
.Text = "Sub "
.FontBold = True: .TextColor = vbRed
.Text = subname
.FontBold = False: .TextColor = vbBlack
.Text = subargs
Else ' print regular paragraph
.Paragraph = ln
End If
Wend
.EndDoc
End With
End Sub
The VPRenderHTML function in the VPUtil.BAS file uses the Text property extensively to render HTML text. If you include the VPUtil.BAS file in your projects, you can use the VPRenderHTML function to render text with embedded formatting. For example:
VPRenderHTML vp, "Hello, this is <B>BOLD</B> and this is <I>ITALICS</I>."
Note: You can also print paragraphs with mixed fonts using the TextRTF property. Using RTF provides a little more flexibility than using the Text property, but rendering RTF takes a lot longer. |
String