printing multiple pages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can't seem to get the logic for printing multiple pages. I know I have to
do a comparison between the bottom margin and the position of the next line
to be printed and initiate a has more pages condition when they are equal. I
have included my code for the printpage handler below. When I run it for an
array that takes up less than a page its OK. When I run it on a larger array
it goes into an infinite loop creating identical pages of the first set of
lines?

Set me straight. (most of this code is setup go to label 1600 for the crux)

Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument2.PrintPage
Try
PrintDocument2.DefaultPageSettings.Landscape = True
PrintDialog2.AllowSomePages = True

Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = FontDialog1.Font.GetHeight(e.Graphics)
Dim XIncrement As Single
Dim i, j As Integer

Dim max As Single = 0
Dim temp(Grid.rows + 1, Grid.cols + 1) As Double
Array.Copy(Grid.array, temp, temp.Length)
For i = 1 To Grid.rows
For j = 1 To Grid.cols
If CStr(temp(i, j)).Length > max Then max = CStr(temp(i,
j)).Length
Next
Next
Dim solidBrush As New solidBrush(FontDialog1.Color)

For i = 1 To Grid.rows
1600: If y + lineheight < e.MarginBounds.Bottom Then
For j = 1 To Grid.cols
e.Graphics.DrawString(CStr(temp(i, j)),
FontDialog1.Font, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Font.SizeInPoints)
+ 10
Next
Else
e.HasMorePages = True
y = 0
GoTo 1600
End If
y += lineheight
Next

Catch ex As Exception
MsgBox(ex.Message)
End Try
end sub
 
Never mind I have it now:

Try
PrintDocument2.DefaultPageSettings.Landscape = True
PrintDialog2.AllowSomePages = True

Dim pagenumber As Integer = 0
Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = FontDialog1.Font.GetHeight(e.Graphics)
Dim XIncrement As Single
Dim i, j, k, p As Integer

Dim max As Single = 0
Dim temp(Grid.rows + 1, Grid.cols + 1) As Double
Array.Copy(Grid.array, temp, temp.Length)
For i = 1 To Grid.rows
For j = 1 To Grid.cols
If CStr(temp(i, j)).Length > max Then max = CStr(temp(i,
j)).Length
Next
Next
Dim solidBrush As New solidBrush(FontDialog1.Color)
'Do
For i = offset To Grid.rows
XIncrement = 0
For j = 1 To Grid.cols
e.Graphics.DrawString(CStr(temp(i, j)),
FontDialog1.Font, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Font.SizeInPoints) + 10
Next
offset += 1
If y + lineheight > e.MarginBounds.Bottom Or offset >
Grid.rows Then Exit For
y += lineheight
Next

If offset < Grid.rows Then
e.HasMorePages = True
Else
offset = 1
End If
 
Back
Top