Sub PrintList()
Dim x As New PrintDocument
AddHandler x.PrintPage, AddressOf printDoc_PrintPage
Dim printHeight As Integer
Dim printWidth As Integer
Dim rightMargin As Integer
Dim tmp As Integer
With x.DefaultPageSettings
printHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
printWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
rightMargin = .Margins.Top 'Y
End With
'x.DefaultPageSettings.Landscape = True
If x.DefaultPageSettings.Landscape Then
tmp = printHeight
printHeight = printWidth
printWidth = tmp
End If
x.Print()
End Sub
Private printLine As Integer = 0
Sub printDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim textToPrint As String = Nothing
Dim printFont As New Font("Courier New", 12)
Dim leftMargin As Integer = e.MarginBounds.Left
Dim topMargin As Integer = e.MarginBounds.Top
Dim startX As Integer = e.MarginBounds.Left
Dim startY As Integer = e.MarginBounds.Top
Dim n As Integer
For Each st As String In LstResults.Items
Dim i As Integer = 0
Dim ar As String() = st.Replace(vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab, vbTab).Replace(vbTab & vbTab & vbTab, vbTab).Split(vbTab)
For Each s As String In ar
i = i + 1
If i <> 4 And i <> 6 And i < 6 Then
textToPrint &= s & " "
ElseIf i = 6 Then
textToPrint &= s & nl & nl
ElseIf i = 4 Then
textToPrint &= nl & s & " "
End If
Next
Next
Dim numLines As Integer = textToPrint.Split("\n").Length
Dim myFont As New Font(LstResults.Font, 8)
Dim myFontBold As New Font("Courier New", 12, FontStyle.Regular)
Dim StringSize As New SizeF
Dim HeightSize As New SizeF
StringSize = e.Graphics.MeasureString(textToPrint, myFont)
Do While printLine < (numLines)
If startY + StringSize.Height > e.MarginBounds.Bottom Then
e.HasMorePages = True
Exit Do
End If
Dim totalout As String() = textToPrint.Split("\n")
e.Graphics.DrawString(totalout(printLine).ToString, LstResults.Font, _
Brushes.Black, startX, startY)
startY += StringSize.Height
printLine += 1
Loop
'e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin)
End Sub