Print multiple copies from single textbox

Harrison

Member
Joined
Oct 29, 2009
Messages
9
Programming Experience
3-5
Hi,

I am trying to send multiple copies to the printer, can anybody help?

Here is my code

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

Dim Numchars As Integer
Dim Numlines As Integer
Dim StringforPage As String
Dim StringFormat As New StringFormat()
Dim Printfont As Font



Printfont = Promo_Print_TextBox.Font

Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)

Dim Sixemeasure As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height - Printfont.GetHeight(e.Graphics))



StringFormat.Trimming = StringTrimming.Word
e.Graphics.MeasureString(StringToPrint, Printfont, Sixemeasure, StringFormat, Numchars, Numlines)
StringforPage = StringToPrint.Substring(0, Numchars)
e.Graphics.DrawString(StringforPage, Printfont, Brushes.Black, rectDraw, StringFormat)



If Numchars < StringToPrint.Length Then


StringToPrint = StringToPrint.Substring(Numchars)

e.HasMorePages = True
Else

e.HasMorePages = False

End If



End Sub

Any help would be very much appreciated. Thanks
 
You configure this with the PrinterSettings, PrintPage handler gets called multiple times automatically. Here is a "manual" example:
VB.NET:
Me.PrintDocument1.PrinterSettings.Copies = 2
You can also use the PrintDialog and connect it to the Document, the dialog has a box where you can set number of copies to print.
 
A little update with some more accurate info; the print handler is not called multiple times like I said, the setting only causes the print job sent to printer to have this additional information that tell the printer how many copies it should output. I just tested this with a file based printer and the driver simply ignored the copies directive, which makes sense. Also, with a breakpoint I saw that the PrintPage handler was only called once. The same job sent to a paper based printer put out the correct number of copies.
 
Back
Top