W
William LaMartin
I am having trouble printing a second page of a what should be a two page
document of the contents of a listview. The "e.HasMorePages = True" line
in the code below is executed, but what should be on a new page is printed
over the top 30 lines of the first page. There are 86 lines to print with
linesPerPage = 56.
What is missing to make the printer use a new piece of paper?
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim linesPerPage As Integer = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Pages = Pages + 1 'originally set to -1
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim line As String = Nothing
' Calculate the number of lines per page.
linesPerPage = Int((e.MarginBounds.Height /
printFont.GetHeight(e.Graphics)))
' Print each item of listview.
Try
While ((count < linesPerPage) And ((count + Pages *
linesPerPage) < Me.ListView1.Items.Count))
line = Me.ListView1.Items(count + Pages *
linesPerPage).ToString
yPos = topMargin + count * printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, New StringFormat)
count += 1
End While
' If more lines exist, print another page.
If ((count + Pages * linesPerPage) < Me.ListView1.Items.Count)
Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
document of the contents of a listview. The "e.HasMorePages = True" line
in the code below is executed, but what should be on a new page is printed
over the top 30 lines of the first page. There are 86 lines to print with
linesPerPage = 56.
What is missing to make the printer use a new piece of paper?
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim linesPerPage As Integer = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Pages = Pages + 1 'originally set to -1
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim line As String = Nothing
' Calculate the number of lines per page.
linesPerPage = Int((e.MarginBounds.Height /
printFont.GetHeight(e.Graphics)))
' Print each item of listview.
Try
While ((count < linesPerPage) And ((count + Pages *
linesPerPage) < Me.ListView1.Items.Count))
line = Me.ListView1.Items(count + Pages *
linesPerPage).ToString
yPos = topMargin + count * printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, New StringFormat)
count += 1
End While
' If more lines exist, print another page.
If ((count + Pages * linesPerPage) < Me.ListView1.Items.Count)
Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub