By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

How to print all pages of the PrintDocument?

P: n/a
Hello to all, I have this form with a PrintDocument named prt_doc,
theproblem is that when I invoke the prt_doc.print() it only prints the las
page, and not multiple pages.
I Also Have a Preview with a PrintPreviewControl and it shows me all the
pages, but I still don´t know how to make them print.
Thank you all
Marcos

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
prt_doc.PrinterSettings.PrintRange = PrintRange.AllPages
prt_doc.Print()
End Sub

Private Sub prt_doc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prt_doc.PrintPage
Dim TipoTexto As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim TipoTexto2 As Font = New Font("Verdana", 8, FontStyle.Bold)
Dim TipoTitulo As Font = New Font("Verdana", 18, FontStyle.Bold)
Dim TipoTitulo2 As Font = New Font("Verdana", 14, FontStyle.Bold)
Dim TipoTitulosDatos As Font = New Font("Verdana", 7,
FontStyle.Underline Or FontStyle.Bold)
Dim TipoDatos As Font = New Font("Verdana", 10, FontStyle.Italic)
Dim Brocha As Brush
Dim Lapiz As Pen = New Pen(Color.Black, 1)
Dim PosY As Integer = e.MarginBounds.Top
If LineaTexto = 0 Then
PosY = e.MarginBounds.Y
Dim Tamano As SizeF = e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.DrawString(Titulo, TipoTitulo, Brushes.Gray, 0, PosY)
PosY += Tamano.Height
e.Graphics.DrawString(Titulo2, TipoTitulo2, Brushes.Black, 0, PosY)
PosY += Tamano.Height + 10
End If
Dim Indice As Integer
Dim AltoLinea As Integer = TipoTexto.GetHeight(e.Graphics) + 2
For Indice = LineaTexto To st_camp0.GetUpperBound(0)
Dim ta_camp1 As SizeF = e.Graphics.MeasureString(st_camp1(Indice),
TipoTexto)
Dim ta_camp4 As SizeF = e.Graphics.MeasureString(st_camp4(Indice),
TipoTexto)
e.Graphics.DrawString(st_camp1(Indice), TipoTexto, Brushes.Black, 2,
PosY + 1)
e.Graphics.DrawLine(Lapiz, 0, PosY, 0, PosY + AltoLinea)
e.Graphics.DrawLine(Lapiz, 0, PosY, 750, PosY)
PosY += AltoLinea
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
If Len(st_camp0(Indice)) = 0 Then Exit For
Next
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Each time the printdocument_printpage event is fired it prints one
page. If you set e.hasmorepages to true it will recall the print document
print event to print a new page. 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
-------------------

"Marcos Beccar Varela" <marcosbv@ga m a c o m .com.ar> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
Hello to all, I have this form with a PrintDocument named prt_doc,
theproblem is that when I invoke the prt_doc.print() it only prints the las
page, and not multiple pages.
I Also Have a Preview with a PrintPreviewControl and it shows me all the
pages, but I still don´t know how to make them print.
Thank you all
Marcos

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
prt_doc.PrinterSettings.PrintRange = PrintRange.AllPages
prt_doc.Print()
End Sub

Private Sub prt_doc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prt_doc.PrintPage
Dim TipoTexto As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim TipoTexto2 As Font = New Font("Verdana", 8, FontStyle.Bold)
Dim TipoTitulo As Font = New Font("Verdana", 18, FontStyle.Bold)
Dim TipoTitulo2 As Font = New Font("Verdana", 14, FontStyle.Bold)
Dim TipoTitulosDatos As Font = New Font("Verdana", 7,
FontStyle.Underline Or FontStyle.Bold)
Dim TipoDatos As Font = New Font("Verdana", 10, FontStyle.Italic)
Dim Brocha As Brush
Dim Lapiz As Pen = New Pen(Color.Black, 1)
Dim PosY As Integer = e.MarginBounds.Top
If LineaTexto = 0 Then
PosY = e.MarginBounds.Y
Dim Tamano As SizeF = e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.DrawString(Titulo, TipoTitulo, Brushes.Gray, 0, PosY)
PosY += Tamano.Height
e.Graphics.DrawString(Titulo2, TipoTitulo2, Brushes.Black, 0, PosY)
PosY += Tamano.Height + 10
End If
Dim Indice As Integer
Dim AltoLinea As Integer = TipoTexto.GetHeight(e.Graphics) + 2
For Indice = LineaTexto To st_camp0.GetUpperBound(0)
Dim ta_camp1 As SizeF = e.Graphics.MeasureString(st_camp1(Indice),
TipoTexto)
Dim ta_camp4 As SizeF = e.Graphics.MeasureString(st_camp4(Indice),
TipoTexto)
e.Graphics.DrawString(st_camp1(Indice), TipoTexto, Brushes.Black, 2,
PosY + 1)
e.Graphics.DrawLine(Lapiz, 0, PosY, 0, PosY + AltoLinea)
e.Graphics.DrawLine(Lapiz, 0, PosY, 750, PosY)
PosY += AltoLinea
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
If Len(st_camp0(Indice)) = 0 Then Exit For
Next
End Sub

Nov 21 '05 #2

P: n/a
Thank You Ken, in the code, in almost the bottom there is these lines.
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If But It isn´t working, it says that when the active line is superior to the
MarginBounds.Bottom, print a new page. So It is generated, As I see in the
previewer, but still not printed.
Thank you again

"Ken Tucker [MVP]" <vb***@bellsouth.net> escribió en el mensaje
news:em*************@TK2MSFTNGP12.phx.gbl... Hi,

Each time the printdocument_printpage event is fired it prints one
page. If you set e.hasmorepages to true it will recall the print document
print event to print a new page. 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
-------------------

"Marcos Beccar Varela" <marcosbv@ga m a c o m .com.ar> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
Hello to all, I have this form with a PrintDocument named prt_doc,
theproblem is that when I invoke the prt_doc.print() it only prints the
las
page, and not multiple pages.
I Also Have a Preview with a PrintPreviewControl and it shows me all the
pages, but I still don´t know how to make them print.
Thank you all
Marcos

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
prt_doc.PrinterSettings.PrintRange = PrintRange.AllPages
prt_doc.Print()
End Sub

Private Sub prt_doc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prt_doc.PrintPage
Dim TipoTexto As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim TipoTexto2 As Font = New Font("Verdana", 8, FontStyle.Bold)
Dim TipoTitulo As Font = New Font("Verdana", 18, FontStyle.Bold)
Dim TipoTitulo2 As Font = New Font("Verdana", 14, FontStyle.Bold)
Dim TipoTitulosDatos As Font = New Font("Verdana", 7,
FontStyle.Underline Or FontStyle.Bold)
Dim TipoDatos As Font = New Font("Verdana", 10, FontStyle.Italic)
Dim Brocha As Brush
Dim Lapiz As Pen = New Pen(Color.Black, 1)
Dim PosY As Integer = e.MarginBounds.Top
If LineaTexto = 0 Then
PosY = e.MarginBounds.Y
Dim Tamano As SizeF = e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.DrawString(Titulo, TipoTitulo, Brushes.Gray, 0, PosY)
PosY += Tamano.Height
e.Graphics.DrawString(Titulo2, TipoTitulo2, Brushes.Black, 0, PosY)
PosY += Tamano.Height + 10
End If
Dim Indice As Integer
Dim AltoLinea As Integer = TipoTexto.GetHeight(e.Graphics) + 2
For Indice = LineaTexto To st_camp0.GetUpperBound(0)
Dim ta_camp1 As SizeF = e.Graphics.MeasureString(st_camp1(Indice),
TipoTexto)
Dim ta_camp4 As SizeF = e.Graphics.MeasureString(st_camp4(Indice),
TipoTexto)
e.Graphics.DrawString(st_camp1(Indice), TipoTexto, Brushes.Black,
2,
PosY + 1)
e.Graphics.DrawLine(Lapiz, 0, PosY, 0, PosY + AltoLinea)
e.Graphics.DrawLine(Lapiz, 0, PosY, 750, PosY)
PosY += AltoLinea
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
If Len(st_camp0(Indice)) = 0 Then Exit For
Next
End Sub

Nov 21 '05 #3

P: n/a
Marcos Beccar Varela wrote:
Thank You Ken, in the code, in almost the bottom there is these lines.
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
But It isn´t working, it says that when the active line is superior to the
MarginBounds.Bottom, print a new page. So It is generated, As I see in the
previewer, but still not printed.
Thank you again

Not sure if I can explain this but after the preview you have to print
it all again.
I think this printdoc stuff stinks!

"Ken Tucker [MVP]" <vb***@bellsouth.net> escribió en el mensaje
news:em*************@TK2MSFTNGP12.phx.gbl...
Hi,

Each time the printdocument_printpage event is fired it prints one
page. If you set e.hasmorepages to true it will recall the print document
print event to print a new page. 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
-------------------

"Marcos Beccar Varela" <marcosbv@ga m a c o m .com.ar> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
Hello to all, I have this form with a PrintDocument named prt_doc,
theproblem is that when I invoke the prt_doc.print() it only prints the
las
page, and not multiple pages.
I Also Have a Preview with a PrintPreviewControl and it shows me all the
pages, but I still don´t know how to make them print.
Thank you all
Marcos

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
prt_doc.PrinterSettings.PrintRange = PrintRange.AllPages
prt_doc.Print()
End Sub

Private Sub prt_doc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prt_doc.PrintPage
Dim TipoTexto As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim TipoTexto2 As Font = New Font("Verdana", 8, FontStyle.Bold)
Dim TipoTitulo As Font = New Font("Verdana", 18, FontStyle.Bold)
Dim TipoTitulo2 As Font = New Font("Verdana", 14, FontStyle.Bold)
Dim TipoTitulosDatos As Font = New Font("Verdana", 7,
FontStyle.Underline Or FontStyle.Bold)
Dim TipoDatos As Font = New Font("Verdana", 10, FontStyle.Italic)
Dim Brocha As Brush
Dim Lapiz As Pen = New Pen(Color.Black, 1)
Dim PosY As Integer = e.MarginBounds.Top
If LineaTexto = 0 Then
PosY = e.MarginBounds.Y
Dim Tamano As SizeF = e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.DrawString(Titulo, TipoTitulo, Brushes.Gray, 0, PosY)
PosY += Tamano.Height
e.Graphics.DrawString(Titulo2, TipoTitulo2, Brushes.Black, 0, PosY)
PosY += Tamano.Height + 10
End If
Dim Indice As Integer
Dim AltoLinea As Integer = TipoTexto.GetHeight(e.Graphics) + 2
For Indice = LineaTexto To st_camp0.GetUpperBound(0)
Dim ta_camp1 As SizeF = e.Graphics.MeasureString(st_camp1(Indice),
TipoTexto)
Dim ta_camp4 As SizeF = e.Graphics.MeasureString(st_camp4(Indice),
TipoTexto)
e.Graphics.DrawString(st_camp1(Indice), TipoTexto, Brushes.Black,
2,
PosY + 1)
e.Graphics.DrawLine(Lapiz, 0, PosY, 0, PosY + AltoLinea)
e.Graphics.DrawLine(Lapiz, 0, PosY, 750, PosY)
PosY += AltoLinea
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
If Len(st_camp0(Indice)) = 0 Then Exit For
Next
End Sub


Nov 21 '05 #4

P: n/a
Thank you Ken, I found this yesterday, I didn´t know that I had to make de
printpage again, but when i took off the previer it began to work. I´ll try
to leave it and invoke the printpage again, thank you
"Jack Russell" <ja***@norubbish.tpg.com.au> escribió en el mensaje
news:eV**************@TK2MSFTNGP14.phx.gbl...
Marcos Beccar Varela wrote:
Thank You Ken, in the code, in almost the bottom there is these lines.
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If


But It isn´t working, it says that when the active line is superior to
the MarginBounds.Bottom, print a new page. So It is generated, As I see
in the previewer, but still not printed.
Thank you again

Not sure if I can explain this but after the preview you have to print it
all again.
I think this printdoc stuff stinks!


"Ken Tucker [MVP]" <vb***@bellsouth.net> escribió en el mensaje
news:em*************@TK2MSFTNGP12.phx.gbl...
Hi,

Each time the printdocument_printpage event is fired it prints one
page. If you set e.hasmorepages to true it will recall the print document
print event to print a new page. 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
-------------------

"Marcos Beccar Varela" <marcosbv@ga m a c o m .com.ar> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
Hello to all, I have this form with a PrintDocument named prt_doc,
theproblem is that when I invoke the prt_doc.print() it only prints the
las
page, and not multiple pages.
I Also Have a Preview with a PrintPreviewControl and it shows me all the
pages, but I still don´t know how to make them print.
Thank you all
Marcos

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
prt_doc.PrinterSettings.PrintRange = PrintRange.AllPages
prt_doc.Print()
End Sub

Private Sub prt_doc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prt_doc.PrintPage
Dim TipoTexto As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim TipoTexto2 As Font = New Font("Verdana", 8, FontStyle.Bold)
Dim TipoTitulo As Font = New Font("Verdana", 18, FontStyle.Bold)
Dim TipoTitulo2 As Font = New Font("Verdana", 14, FontStyle.Bold)
Dim TipoTitulosDatos As Font = New Font("Verdana", 7,
FontStyle.Underline Or FontStyle.Bold)
Dim TipoDatos As Font = New Font("Verdana", 10, FontStyle.Italic)
Dim Brocha As Brush
Dim Lapiz As Pen = New Pen(Color.Black, 1)
Dim PosY As Integer = e.MarginBounds.Top
If LineaTexto = 0 Then
PosY = e.MarginBounds.Y
Dim Tamano As SizeF = e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.MeasureString(Titulo, TipoTitulo)
e.Graphics.DrawString(Titulo, TipoTitulo, Brushes.Gray, 0, PosY)
PosY += Tamano.Height
e.Graphics.DrawString(Titulo2, TipoTitulo2, Brushes.Black, 0,
PosY)
PosY += Tamano.Height + 10
End If
Dim Indice As Integer
Dim AltoLinea As Integer = TipoTexto.GetHeight(e.Graphics) + 2
For Indice = LineaTexto To st_camp0.GetUpperBound(0)
Dim ta_camp1 As SizeF = e.Graphics.MeasureString(st_camp1(Indice),
TipoTexto)
Dim ta_camp4 As SizeF = e.Graphics.MeasureString(st_camp4(Indice),
TipoTexto)
e.Graphics.DrawString(st_camp1(Indice), TipoTexto, Brushes.Black,
2,
PosY + 1)
e.Graphics.DrawLine(Lapiz, 0, PosY, 0, PosY + AltoLinea)
e.Graphics.DrawLine(Lapiz, 0, PosY, 750, PosY)
PosY += AltoLinea
If PosY + AltoLinea >= e.MarginBounds.Bottom Then
LineaTexto = Indice
PosY = e.MarginBounds.Top
e.HasMorePages = True
Exit Sub
End If
If Len(st_camp0(Indice)) = 0 Then Exit For
Next
End Sub



Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.