Private StreamToPrint As IO.StreamReader
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim LinesPerPage As Single = e.MarginBounds.Height / PrintFont.GetHeight(e.Graphics)
Dim Line As String = Nothing, count As Integer, yPos As Single = 0
For count = 0 To LinesPerPage - 1
Line = StreamToPrint.ReadLine
If Line Is Nothing Then Exit For
yPos = e.MarginBounds.Top + count * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Line, PrintFont, Brushes.Black, e.MarginBounds.Left, yPos, New StringFormat())
Next
If Not (Line Is Nothing) Then e.HasMorePages = True
End Sub
Private Sub MenuItemPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPrint.Click
StreamToPrint = New IO.StreamReader("temp.xml")
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
If Not (StreamToPrint Is Nothing) Then
StreamToPrint.Close()
End If
End If
End Sub