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..

Thanks

Hi,

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 
    fnt.Dispose() 
  End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.