Fred Kane


This is my code; I expect two pages of output, but get only one.

'one button on form, used default names and settings for everything

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

PrintDocument1.DefaultPageSettings.Landscape = False 'portrait mode

PrintDocument1.Print() 'begin print

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, _

ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim nFont As New System.Drawing.Font("Arial", 12, FontStyle.Regular) 'any font will do

e.Graphics.DrawString("Printed on page 1", nFont, Brushes.Black, 250, 400)

e.HasMorePages = True 'go to the next page

e.Graphics.DrawString("Printed on page 2", nFont, Brushes.Black, 250, 600) 'still printed on page 1!

e.HasMorePages = False 'if I omit this, printing continues until I abort it

End Sub

What am I doing wrong

Fred :-(---//



Re: Unexpected results from PrintDocument1 PrintPage event

Tall Dude


Public Class Form1

Dim CurrentPage As Integer = 1

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

PrintDocument1.DefaultPageSettings.Landscape = False 'portrait mode

' PrintDocument1.Print() 'begin print

' Use a print preview while debugging, to save time and paper

' Next line can be set in the IDE

PrintPreviewDialog1.Document = PrintDocument1

PrintPreviewDialog1.ShowDialog()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, _

ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim nFont As New System.Drawing.Font("Arial", 12, FontStyle.Regular)

If CurrentPage = 1 Then

e.Graphics.DrawString("Printed on page 1", nFont, Brushes.Black, 250, 400)

CurrentPage += 1

e.HasMorePages = True

Exit Sub

Else

e.Graphics.DrawString("Printed on page 2", nFont, Brushes.Black, 250, 600)

e.HasMorePages = False

' Reset any and all logic values that your PrintPage will use here!!!!

' If the print button in print preview is pressed, the printpage

' code is run again from the beginning. (The print controller changes

' from 'preview' to 'print' behind the scenes.

CurrentPage = 1

End If

' e.HasMorePages is used to call the sub again or not

' and is only used when 'end sub' is reached.

End Sub

End Class






Re: Unexpected results from PrintDocument1 PrintPage event

JohnWein

Code Block

Private PagePrinting As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

PagePrinting = 0

PrintDocument1.DefaultPageSettings.Landscape = False 'portrait mode

PrintDocument1.Print() 'begin print

End Sub

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

Dim nFont As New System.Drawing.Font("Arial", 12, FontStyle.Regular) 'any font will do

PagePrinting += 1

Select Case PagePrinting

Case 1

e.Graphics.DrawString("Printed on page 1", nFont, Brushes.Black, 250, 400)

e.HasMorePages = True 'go to the next page

Case 2

e.Graphics.DrawString("Printed on page 2", nFont, Brushes.Black, 250, 600)

End Select






Re: Unexpected results from PrintDocument1 PrintPage event

Fred Kane

John & TallDude,

Thank you. I see that I have to control things much more explicitly than I'm used to. I'd've been perfectly happy with C:copy filename.txt lpt1:....

Fred :-{)}---//





Re: Unexpected results from PrintDocument1 PrintPage event

JohnWein

Yeh. It was easier to output to a 110 baud teletype.