Check for a line longer than the page width and print the remaining text on the next line(s). There is no automatic text wrapping to the next line.
This example has not been tested.
Note: This example does not handle the case of an extremely long line that would overflow the end of the page and should cause a new page.
Private Sub objprintDocument_Printpage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim sngLinesPerPage As Single = 0
Dim sngVerticalPosition As Single = 0
Dim intLineCount As Integer = 0
Dim sngLeftMargin As Single = e.MarginBounds.Left
Dim sngTopMargin As Single = e.MarginBounds.Top
Dim strLine As String
sngLinesPerPage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics)
strLine = objStreamToPrint.ReadLine()
While (intLineCount < sngLinesPerPage And Not (strLine Is Nothing))
sngVerticalPosition = sngTopMargin + (intLineCount * objPrintFont.GetHeight(e.Graphics))
Const intLineWidth As Integer = 90
While strLine.Length > 0
e.Graphics.DrawString( _
strLine.Substring(0, Math.Min(strLine.Length, intLineWidth)), _
objPrintFont, Brushes.Black, _
sngLeftMargin, sngVerticalPosition, New StringFormat)
intLineCount += 1
If strLine.Length = intLineWidth Then
strLine = ""
Else
strLine = strLine.Substring(intLineWidth)
End If
End While
If intLineCount < sngLinesPerPage Then
strLine = objStreamToPrint.ReadLine
End If
End While
If (strLine <> Nothing) Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub