M
Mr. B
VB.net (standard)
I'm experiencing some difficulties in printing multiple pages using Print
Preview.
The following is my main parts of my printing subs (excess info deleted for
your viewing pleasure). For a single page, the print preview (and an actual
print) are OK. Getting the .HasMorePages doesn't seem to be working for me
here (unless I'm missing something).
I have a Title Block (separate sub)... print my info 'group' (max 10 per
page)... What the following does (and it's at the bottom where I'm screwing
up) is that 10 or Less items is OK. More than 10 items gives me ONE page with
all the data printed over each other (ie: a Page Break does not occur).
I'd appreciate some help here (have spent many hours trying to figure this one
out):
' ***********************************************************
Private Sub mnuPrinter_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPrinter.Click
... I set up my PageSettings, Fonts, Column Widths, DefaultPageSettings, etc.
here...
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
' ***********************************************************
Private Sub PrintDocHeader(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
.... I set up my Document Header stuff here...
End Sub
' ***********************************************************
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim rwCntr As Integer = 0 ' Print Rows Counter (max 16 used)
Dim str As String
' Start Printing Output
For cntrI = 0 To lbWeekItems.Items.Count - 1
rwCntr = rwCntr + 1
' Page Header
If rwCntr = 1 Then PrintDocHeader(e)
.... Now I print my rows (group) of info...
Dim HrTtl As Double
Dim R1 As New RectangleF(X1, Y, W1, 80) ' Col 1 Job
Dim R2 As New RectangleF(X1 + 80, Y, W2, 80) ' Col 2 Job Desc
str = ProjArray(0, cntrI + 1)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R1)
str = ProjArray(1, cntrI + 1)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R2)
..... etc, etc...
.... I Finish off my items with a row (between each group of items)...
Y = Y + 15
' Draw Break Line
With PrintDocument1.DefaultPageSettings
Y = Y + 20
e.Graphics.DrawLine(Pens.Black, X1, Y, .PaperSize.Height - 50, Y)
End With
' HERE IS WHERE I THINK THE PROBLEM IS???
' ========================================
If rwCntr = 10 Then
e.HasMorePages = True
rwCntr = 0
End If
Next ' cntrI
' No More Pages to Print
e.HasMorePages = False
End Sub
Thanks!
Bruce
I'm experiencing some difficulties in printing multiple pages using Print
Preview.
The following is my main parts of my printing subs (excess info deleted for
your viewing pleasure). For a single page, the print preview (and an actual
print) are OK. Getting the .HasMorePages doesn't seem to be working for me
here (unless I'm missing something).
I have a Title Block (separate sub)... print my info 'group' (max 10 per
page)... What the following does (and it's at the bottom where I'm screwing
up) is that 10 or Less items is OK. More than 10 items gives me ONE page with
all the data printed over each other (ie: a Page Break does not occur).
I'd appreciate some help here (have spent many hours trying to figure this one
out):
' ***********************************************************
Private Sub mnuPrinter_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPrinter.Click
... I set up my PageSettings, Fonts, Column Widths, DefaultPageSettings, etc.
here...
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
' ***********************************************************
Private Sub PrintDocHeader(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
.... I set up my Document Header stuff here...
End Sub
' ***********************************************************
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim rwCntr As Integer = 0 ' Print Rows Counter (max 16 used)
Dim str As String
' Start Printing Output
For cntrI = 0 To lbWeekItems.Items.Count - 1
rwCntr = rwCntr + 1
' Page Header
If rwCntr = 1 Then PrintDocHeader(e)
.... Now I print my rows (group) of info...
Dim HrTtl As Double
Dim R1 As New RectangleF(X1, Y, W1, 80) ' Col 1 Job
Dim R2 As New RectangleF(X1 + 80, Y, W2, 80) ' Col 2 Job Desc
str = ProjArray(0, cntrI + 1)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R1)
str = ProjArray(1, cntrI + 1)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R2)
..... etc, etc...
.... I Finish off my items with a row (between each group of items)...
Y = Y + 15
' Draw Break Line
With PrintDocument1.DefaultPageSettings
Y = Y + 20
e.Graphics.DrawLine(Pens.Black, X1, Y, .PaperSize.Height - 50, Y)
End With
' HERE IS WHERE I THINK THE PROBLEM IS???
' ========================================
If rwCntr = 10 Then
e.HasMorePages = True
rwCntr = 0
End If
Next ' cntrI
' No More Pages to Print
e.HasMorePages = False
End Sub
Thanks!
Bruce