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

how to creat and print multi page document

P: 11
I have been tring to recreate a simple program that I wrote many years ago in quick basic. The program get name and address from a database, then the user will enter in info like order #, po # and starting box then number of boxes.

In quick basic it was easy to send a form feed and print the next label. But this visual basic .net stuff has me pulling my hair out. I can print all the info to desired printer. But do not understand how to created a multi page document to send. I could have it loop through all the box numbers and call the print routine multiply time but This would send many seperate print jobs.
I will paste code below (it's not pretty) I'll start with the print button code and then jump to the class it is calling to.

Hope someone can make sense of this and maybe even help me,
David DeWitt


Public Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click

Dim Print As New myPrinter
Call Print.prt()

End Sub

Public Class myPrinter

Public Sub prt()

Dim prn As New Drawing.Printing.PrintDocument
Using (prn)
prn.PrinterSettings.PrinterName = My.Settings.Printer
AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
End Using
End Sub

Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Drawing.Printing.PrintPageEventArgs)
Dim smFont As New Font("Microsoft San Serif", 10)
Dim medFont As New Font("Microsoft San Serif", 14)
Dim lrgFont As New Font("Microsoft San Serif", 18)
Dim startlbl As Integer = MainForm.txtStartBoxNUmber.Text
Dim endlbl As Integer = MainForm.txtStartBoxNUmber.Text + MainForm.txtBoxes.Text

Do Until startlbl = endlbl

' return address
args.Graphics.DrawImage(My.Resources.LOGO_2, 60, 10)
args.Graphics.DrawString(My.Settings.returnAddress , New Font(smFont, FontStyle.Regular), Brushes.Black, 117, 70)
args.Graphics.DrawString(My.Settings.returnCity, New Font(smFont, FontStyle.Regular), Brushes.Black, 110, 85)
' ship to address
args.Graphics.DrawString("Ship to:", New Font(medFont, FontStyle.Bold), Brushes.Black, 5, 150)
args.Graphics.DrawString(MainForm.txtCompanyName.T ext, New Font(lrgFont, FontStyle.Bold), Brushes.Black, 30, 175)
args.Graphics.DrawString(MainForm.txtAttn.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 210)
args.Graphics.DrawString(MainForm.txtAddress1.Text , New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 235)
args.Graphics.DrawString(MainForm.txtAddress2.Text , New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 260)
args.Graphics.DrawString(MainForm.txtCity.Text & ", " & MainForm.txtState.Text & " " & MainForm.txtZip.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 285)
' Package & Order information
args.Graphics.DrawString("P.O. #" & MainForm.txtPO.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 370)
args.Graphics.DrawString("Order #" & MainForm.txtOrderNumber.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 390)
args.Graphics.DrawString("Box #" & startlbl, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 410)
startlbl = startlbl + 1
args.HasMorePages = True

args.HasMorePages = False

End Sub
End Class

Dec 10 '06 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
Sorry to see you're not getting any response here in the VB forum. You might try posting your question in the .NET forum, to see whether anyone over there can help.
Dec 11 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.