T
tghamm
Ok, so this is driving me mad. For some reason, regardless of the
value of ev.hasmorepages, the printoducment1_printpage gets called
twice for every page. So, I print 2 pages of data on one page, with
the second overlaying the original data. If i set ev.hasmorepages to
false, essentially telling the printdocument to only print one page,
it prints one page, with two pages of data, because at the end of the
_printpage subroutine, even when ev.hasmorepages is false, it runs the
sub once more. Any help on this would be fantastic, below is my code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal ev As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
'ev.HasMorePages = True
' Calculate the number of lines per page.
linesPerPage = (ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics)) - 1
' Print each line of the file.
'If counterx = False Then
While count < linesPerPage
line = streamtoprint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count *
printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, New StringFormat())
count += 1
End While
'End If
'If counterx = False Then
'counterx = True
'ElseIf counterx = True Then
'counterx = False
'End If
' If more lines exist, print another page.
If (line IsNot Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
...........THIS IS WHAT CALLS THE PRINTPAGE....
streamtoprint = New IO.StreamReader("C:\temp.dat")
Try
printFont = New Font("Times New Roman", 10)
AddHandler PrintDocument1.PrintPage, AddressOf
Me.PrintDocument1_PrintPage
PrintDocument1.Print()
Finally
streamtoprint.Close()
IO.File.Delete("C:\temp.dat")
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Thanks everyone!
value of ev.hasmorepages, the printoducment1_printpage gets called
twice for every page. So, I print 2 pages of data on one page, with
the second overlaying the original data. If i set ev.hasmorepages to
false, essentially telling the printdocument to only print one page,
it prints one page, with two pages of data, because at the end of the
_printpage subroutine, even when ev.hasmorepages is false, it runs the
sub once more. Any help on this would be fantastic, below is my code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal ev As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
'ev.HasMorePages = True
' Calculate the number of lines per page.
linesPerPage = (ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics)) - 1
' Print each line of the file.
'If counterx = False Then
While count < linesPerPage
line = streamtoprint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count *
printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, New StringFormat())
count += 1
End While
'End If
'If counterx = False Then
'counterx = True
'ElseIf counterx = True Then
'counterx = False
'End If
' If more lines exist, print another page.
If (line IsNot Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
...........THIS IS WHAT CALLS THE PRINTPAGE....
streamtoprint = New IO.StreamReader("C:\temp.dat")
Try
printFont = New Font("Times New Roman", 10)
AddHandler PrintDocument1.PrintPage, AddressOf
Me.PrintDocument1_PrintPage
PrintDocument1.Print()
Finally
streamtoprint.Close()
IO.File.Delete("C:\temp.dat")
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Thanks everyone!