I have asked before and got little responce, So I try and try again.
The code below prints the data in the same place but does not advance the page. I can see the lblnumber change but print in top of the previous one. So my loop is working, I have the hasmorepages= true set right after each cycle till the loop finishes.
Hopefully someone can point out my error.
Thanks David DeWitt
this part calls the printing code
here is my printing code
The code below prints the data in the same place but does not advance the page. I can see the lblnumber change but print in top of the previous one. So my loop is working, I have the hasmorepages= true set right after each cycle till the loop finishes.
Hopefully someone can point out my error.
Thanks David DeWitt
this part calls the printing code
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
Code:
Imports System.Drawing.Printing Public Class myPrinter Public Shared lblnumber As Integer Public Shared endlbl As Integer Private WithEvents prn As PrintDocument Public Sub prt() Dim prn As New PrintDocument ' Create a PaperSize and specify the custom paper size . Dim pkCustomSize1 As New PaperSize("Label Size", 400, 800) Using (prn) prn.PrinterSettings.PrinterName = My.Settings.Printer 'to add page size here. prn.DefaultPageSettings.PaperSize = pkCustomSize1 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 System.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) lblnumber = CInt(MainForm.txtStartBoxNUmber.Text) endlbl = CInt(MainForm.txtStartBoxNUmber.Text) + CInt(MainForm.txtBoxes.Text) Do ' 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.Text, 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 #" & lblnumber, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 410) lblnumber = lblnumber + 1 args.HasMorePages = True Loop Until lblnumber = endlbl args.HasMorePages = False End Sub End Class
Comment