Printdocument hadmorepages

  • Thread starter Stijn Vanpoucke
  • Start date
S

Stijn Vanpoucke

Hallo, i'm having troubles by printing on more pages.

I have a counter in the PrintDocument1_PrintPage(..) and i would like to
start a new page every 3 counts.

If tried it this way:

If (i + 1) Mod 3 = 0 Then
e.HasMorePages = True

End If




Part of my code:

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Try

e.Graphics.DrawString("TKD", New Font("Arial", 20, FontStyle.Bold),
Brushes.DarkGreen, 60, 50)

e.Graphics.DrawString("Overzicht Leveranciers", New Font("Arial", 15,
FontStyle.Bold), Brushes.Black, 60, 100)

e.Graphics.DrawString("-----------------------------------------------------
------------------------------------", New Font("Arial", 15,
FontStyle.Bold), Brushes.Black, 60, 120)

Dim i As Int32

For i = 0 To DgridLeveranciers.VisibleRowCount - 2

Dim Hoogte As Int32 = i * 320

'titels

e.Graphics.DrawString("id:", New Font("Arial", 10, FontStyle.Regular),
Brushes.Black, 400, 170 + Hoogte)

e.Graphics.DrawString("Firmanaam:", New Font("Arial", 12, FontStyle.Bold),
Brushes.Black, 70, 170 + Hoogte)

....


'gegevens

e.Graphics.DrawString(DgridLeveranciers.Item(i, 0), New Font("Arial", 10,
FontStyle.Regular), Brushes.Black, 420, 170 + Hoogte)

e.Graphics.DrawString(DgridLeveranciers.Item(i, 1), New Font("Arial", 12,
FontStyle.Bold), Brushes.Black, 190, 170 + Hoogte)

........

If (i + 1) Mod 3 = 0 Then

e.HasMorePages = True

End If

Next i

'aanduiden dat dit de laatste pagina is

e.HasMorePages = False

Catch

MessageBox.Show("Er is een fout opgetreden: " & vbCrLf & Err.Number & ": " &
Err.Description, "Fout!", MessageBoxButtons.OK, MessageBoxIcon.Warning)

End Try

End Sub
 
A

Armin Zingler

Stijn Vanpoucke said:
Hallo, i'm having troubles by printing on more pages.

I have a counter in the PrintDocument1_PrintPage(..) and i would like
to start a new page every 3 counts.

[...]

For i = 0 To DgridLeveranciers.VisibleRowCount - 2

[...]

If (i + 1) Mod 3 = 0 Then

e.HasMorePages = True

End If

Next i

'aanduiden dat dit de laatste pagina is

e.HasMorePages = False


It doesn't make sense to set e.HasMorePages /within/ the loop because you
overwrite the value /after/ the loop. The printpage event is raised once per
page. After you printed the page (Drawstring), set e.HasMorePages to
indicate whether another page should be printed.



--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
K

Ken Tucker [MVP]

Hi,

If you set e.hasmorepages to true it will recall the print document
print event to print a new page. It does not start a new page then. Here
is a simple example.

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics
Static intItem As Integer = 0
Dim y As Integer = 0
Dim bDraw As Boolean = True

Do Until Not bDraw
y += 15
g.DrawString(intItem.ToString, Me.Font, Brushes.Black, 10, y)
intItem += 1
bDraw = (intItem Mod 3 <> 0)
Loop

If intItem = 18 Then
intItem = 0
Else
e.HasMorePages = True
End If
End Sub

Ken
 
S

Stijn Vanpoucke

thanks a lot I managed to get it work!


Ken Tucker said:
Hi,

If you set e.hasmorepages to true it will recall the print document
print event to print a new page. It does not start a new page then. Here
is a simple example.

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics
Static intItem As Integer = 0
Dim y As Integer = 0
Dim bDraw As Boolean = True

Do Until Not bDraw
y += 15
g.DrawString(intItem.ToString, Me.Font, Brushes.Black, 10, y)
intItem += 1
bDraw = (intItem Mod 3 <> 0)
Loop

If intItem = 18 Then
intItem = 0
Else
e.HasMorePages = True
End If
End Sub

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top