InertiaM
Well-known member
I'm just learning how to convert my VB6 printing code to VB.NET. I've looked through most of the articles on here, but I cant find one that relates to my problem.
I want to print two pages. Standard laser printer, nothing special. When I call myPrinter.TestPrint(), what I actually get is one page with both pages printed onto one. In other words it shows "Test page 1" and "Test page 2" on the first page, and I dont get a second page.
I'm sure it's a basic error, but I cant find it. Any ideas please ?
I want to print two pages. Standard laser printer, nothing special. When I call myPrinter.TestPrint(), what I actually get is one page with both pages printed onto one. In other words it shows "Test page 1" and "Test page 2" on the first page, and I dont get a second page.
I'm sure it's a basic error, but I cant find it. Any ideas please ?
VB.NET:
Class myPrinter
Private WithEvents pd As New PrintDocument()
Private shtPageNumber As Int16 = 0
Private shtTotalPages As Int16 = 0
Public Sub TestPrint()
pd.DocumentName = "Test Document"
pd.PrintController = New Printing.StandardPrintController()
AddHandler pd.BeginPrint, AddressOf Begin_Printing
AddHandler pd.PrintPage, AddressOf Test_PrintPage
shtTotalPages = 2
Try
pd.Print()
Catch e As Exception
MessageBox.Show("An error occurred !" & vbCrLf & vbCrLf & e.Message)
End Try
RemoveHandler pd.PrintPage, AddressOf Test_PrintPage
RemoveHandler pd.BeginPrint, AddressOf Begin_Printing
End Sub
Private Sub Begin_Printing(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles pd.BeginPrint
shtPageNumber = 0
End Sub
Private Sub Test_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage
shtPageNumber += 1
Dim f As New Font("Arial", 18, FontStyle.Bold)
e.Graphics.DrawString("TEST PAGE " & shtPageNumber.ToString(), f, Brushes.Black, 15, 12 * shtPageNumber)
If shtPageNumber < shtTotalPages Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
End Class