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
/CODE/
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
prn.Print()
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
Loop
args.HasMorePages = False
End Sub
End Class
/CODE/