e.hasmorepages???????????

G

Guest

hello all.....
I can currently print out only one page with the following code...(note it
lacks the e.hasmorepages=false)

Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles PrintToolStripButton.Click
'Print file from the ToolStrip
Me.PrintDialog1.ShowDialog()
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'Print Function to call
e.Graphics.DrawString(Me.RichTextBox1.Text, New Font("Courier New",
10, FontStyle.Regular), Brushes.Black, 0, 0)

End Sub

This prints out 1 pg and 1 pg only....regardless if there's more or not.

I searched dotnet.general for discussions on this subject and found out
about e.hasmorepages.....however, when I use it in my code the printpage
count thingy goes
crazy.....just multiplies (100 pages +) my printer don't like this :)

Can anyone shed any light on this for me? Maybe help me to print out exactly
how many pages I actually have and not 100's or just 1?

My code looks like this.....

Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles PrintToolStripButton.Click
'Print file from the ToolStrip
Me.PrintDialog1.ShowDialog()
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'Print Function to call
e.Graphics.DrawString(Me.RichTextBox1.Text, New Font("Courier New",
10, FontStyle.Regular), Brushes.Black, 0, 0)
e.HasMorePages = True
End Sub

Thank you much!!!!!!!!!

Brenton (long-winded) Garman
 
J

Jason Hales

You are responsible for telling PrintPage if you have any more pages to
print - by setting e.HasMorePages = True.

It won't do it for you - the same event gets called repeatedly each
time you set e.HasMorePages = True

It all depends on what you're trying to print out. It's normally a
case of working out how many pages there are based on the amount of
text/images you want to print and how they fit into the
PrintPageEventArgs.MarginBounds.

You can use PrintPageEventArgs.e.Graphics.MeasureString("text", myFont)
to measure the size of a string in the selected font to see how big it
will be on the page.

The PrintDocument help has good sample.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top