Hi guys...

I am in need of urgent help here!
I want to print more than one page on vb.net's printdocument whatever!
I quite don't get it quite clearly when it comes to "e.hasmorepages=true" thing
It keeps adding pages on and on and on...
Please help me..


6 Years
Discussion Span
Last Post by Luc001


Here's an example how to do it:

Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint 
    '--- Start printing at the start of the string 
    mStringPos = 0 
  End Sub 

  Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 
    '--- Setup graphics context 
    Dim fnt As New Font("Arial", 10) 
    e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias 
    '--- Calculate the number of characters that fit inside the margins 
    Dim area As SizeF = New SizeF(e.MarginBounds.Width, e.MarginBounds.Height) 
    Dim lines, chars As Integer 
    e.Graphics.MeasureString(PrintText.Substring(mStringPos), fnt, area, _ 
      StringFormat.GenericTypographic, chars, lines) 
    '--- Print the amount of text that fits inside the margins 
    Dim rc As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height) 
    e.Graphics.DrawString(PrintText.Substring(mStringPos, chars), fnt, _ 
      Brushes.Black, rc, StringFormat.GenericTypographic) 
    '--- Advance print position by <chars> 
    mStringPos += chars 
    '--- We'll need another page if not all characters got printed 
    e.HasMorePages = mStringPos < PrintText.Length 
    '--- Cleanup 
  End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.