Class

StyledTextPrinter


Description

Used to print styled text stored in a TextArea.

Properties

Name

Type

Read-Only

Shared

EOF

Boolean

Width

Integer

Methods

Name

Parameters

Returns

Shared

DrawBlock

x As Integer, y As Integer, Height As Integer

Property descriptions


StyledTextPrinter.EOF

EOF As Boolean

True when there is no more text to print in the TextArea.

This property is read-only.

Use it to determine when to stop calling DrawBlock. See the examples.


StyledTextPrinter.Width

Width As Integer

The width of the text to be printed.

Method descriptions


StyledTextPrinter.DrawBlock

DrawBlock(x As Integer, y As Integer, Height As Integer)

Used to print the styled text.

The parameters x and y are coordinates of the point at which you want to begin printing the text. x and y are offset from the top-left corner of the printable area as defined in Page Setup.

Notes

StyledTextPrinter is not supported on Windows and will raise an UnsupportedOperationException if called.

Sample code

The following code prints the styled text in a TextArea. The TextArea's MultiLine and Styled properties must be set to True to accept and print styled text.

Var stp As StyledTextPrinter
Var g As Graphics
g = OpenPrinterDialog
If g <> Nil Then
  ' 72 pixels per inch * 7.5 inches
  Var textWidth As Integer = 72 * 7.5
  stp = TextArea1.StyledTextPrinter(g, textWidth)
  stp.DrawBlock(0, 0, 72 * 10)
End If

This code prints the contents of TextArea1 in two columns with a quarter-inch of spacing between them. The EOF property is used to determine if all the text has been printed. When EOF is False, it prints the second column or prints another page.

Var g As Graphics
Var stp As StyledTextPrinter
Var columnWidth, spaceBetweenColumns, pageHeight As Integer
Var columnToPrint As Integer
columnWidth = 261
' 7.5 inches minus 1/4 inch for space
' divided by 2
spaceBetweenColumns = 18
' 18 pixels is 1/4 inch
pageHeight = 10 * 72
' 10 inches * 72 pixels per inch
g = OpenPrinterDialog
If g <> Nil Then
  stp = TextArea1.StyledTextPrinter(g, 540)
  stp.Width = columnWidth
  columnToPrint = 1
  Do Until stp.EOF
    stp.DrawBlock((columnWidth + spaceBetweenColumns) * (columnToPrint - 1), 0, PageHeight)
    If columnToPrint = 2 Then ' printing last column
      If Not stp.EOF Then ' more text to print
        g.NextPage
        columnToPrint = 1
      End If
    Else ' more columns to print on this page
      columnToPrint = columnToPrint + 1
    End If
  Loop
End If

Compatibility

All project types on all supported operating systems.

See also

Object parent class; TextArea control; PrinterSetup.OpenPrinter, ShowPrinterDialog functions; Graphics, PrinterSetup classes.