Printing multiple pages

Joined
May 31, 2003
Messages
5
hey all...

got a bit of probs when printing multiple pages... i can print one page nicely, when there is only enough text for one page, but when i hit multiple pages, all goes to heck....

i use the e.hasmorepages = true method, but it spits out unlimited pages...

how do i get it to print the remaining text on new pages when need be?

Thanks
 
when setting has hasmorepages what happes is that the
printerdocument printpage sub is called again.

What you need is a way to determin if your at the end of the document you want to print and if you are to set the following

Code:
e.hasmorepages = false

If your having problem after looking at you code post the print document sub up so we can have a look

Andy
 
Ok, there is two parts to this print code (since the transaction array is within the savingsAccount class). In the winForm class, there is:

Code:
Dim sngXVal As Single
        Dim sngYVal As Single
        Dim intIncrement As Integer
        Dim strOutput As String
        Dim headingFont As New Font("Arial", 28, FontStyle.Bold)
        Dim mainFont As New Font("Times New Roman", 12, FontStyle.Regular)
        Dim subSectionFont As New Font("Arial", 22, FontStyle.Bold)
        Dim blackPen As New Pen(Color.Black, 3)
        Dim intCounter As Integer

        sngXVal = e.MarginBounds.Left
        sngYVal = e.MarginBounds.Top

        e.Graphics.DrawRectangle(blackPen, e.PageBounds.Left + 100, _
            e.PageBounds.Top + 100, e.PageBounds.Right - 200, _
            e.PageBounds.Bottom - 200)

        sngXVal += 10
        sngYVal += 10

        e.Graphics.DrawString("Your Transaction History", headingFont, Brushes.Black, _
            (sngXVal + 30), sngYVal)

        sngYVal += 90
        sngXVal += 10

        e.Graphics.DrawString("Account Details", subSectionFont, Brushes.Black, _
            sngXVal, sngYVal)

        sngYVal += 32
        e.Graphics.DrawString("Account Number: ", mainFont, _
            Brushes.Black, sngXVal, sngYVal)
        e.Graphics.DrawString(CStr(mySavingsAccount.AccountNumber), mainFont, _
            Brushes.Black, (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Account Name: ", mainFont, _
            Brushes.Black, sngXVal, sngYVal)
        e.Graphics.DrawString(mySavingsAccount.AccountName, mainFont, Brushes.Black, _
            (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Bank Name: ", mainFont, Brushes.Black, _
            sngXVal, sngYVal)
        e.Graphics.DrawString(mySavingsAccount.BankName, mainFont, _
            Brushes.Black, (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Branch Number: ", mainFont, Brushes.Black, _
            sngXVal, sngYVal)
        e.Graphics.DrawString(CStr(mySavingsAccount.BranchNumber), mainFont, _
            Brushes.Black, (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Opening Balance: ", mainFont, Brushes.Black, _
            sngXVal, sngYVal)
        e.Graphics.DrawString(CStr(mySavingsAccount.OpeningBalance), mainFont, _
            Brushes.Black, (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Closing Balance: ", mainFont, Brushes.Black, _
            sngXVal, sngYVal)
        e.Graphics.DrawString(CStr(mySavingsAccount.ClosingBalance), mainFont, _
                    Brushes.Black, (sngXVal + 200), sngYVal)
        sngYVal += 20
        e.Graphics.DrawString("Minimum Transaction: ", mainFont, Brushes.Black, _
            sngXVal, sngYVal)
        e.Graphics.DrawString(CStr(mySavingsAccount.TransactionMinimumBalance), _
            mainFont, Brushes.Black, (sngXVal + 200), sngYVal)

        sngYVal += 45
        e.Graphics.DrawString("Transactions", subSectionFont, Brushes.Black, _
            sngXVal, sngYVal)
        sngYVal += 32

        mySavingsAccount.PrintTransactions(sender, e, mainFont, sngXVal, sngYVal)





Then in the savings Account Sub:

Public Sub PrintTransactions(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs, _
        ByVal font As Font, ByVal sngXVal As Single, ByVal sngYVal As Single)
        Dim intPass As Integer
        Dim intIndex As Integer
        Dim datBuffer As Date

        For intPass = 1 To RecordTransaction.GetUpperBound(0)
            For intIndex = 0 To RecordTransaction.GetUpperBound(0) - 1
                If RecordTransaction(intIndex).TransactionDate > RecordTransaction(intIndex + 1).TransactionDate Then
                    datBuffer = RecordTransaction(intIndex).TransactionDate
                    RecordTransaction(intIndex).TransactionDate = RecordTransaction(intIndex + 1).TransactionDate
                    RecordTransaction(intIndex + 1).TransactionDate = datBuffer
                End If
            Next
        Next

        Dim intCounter As Integer
        For intCounter = (RecordTransaction.GetLowerBound(0)) To (RecordTransaction.GetUpperBound(0))

            e.Graphics.DrawString("Account Type: ", font, Brushes.Blue, sngXVal, _
                    sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).AccType), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 20
            e.Graphics.DrawString("Transaction Type: ", font, Brushes.Black, _
                    sngXVal, sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).TransactionType), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 20
            e.Graphics.DrawString("Transaction Description: ", font, Brushes.Black, _
                sngXVal, sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).TransactionDescription), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 20
            e.Graphics.DrawString("Amount: ", font, Brushes.Black, _
                sngXVal, sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).Amount), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 20
            e.Graphics.DrawString("Date: ", font, Brushes.Black, _
                sngXVal, sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).TransactionDate), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 20
            e.Graphics.DrawString("Indicator: ", font, Brushes.Black, _
                sngXVal, sngYVal)
            e.Graphics.DrawString((RecordTransaction(intCounter).Indicator), font, _
                Brushes.Black, (sngXVal + 200), sngYVal)
            sngYVal += 32
        Next intCounter
    End Sub
 
Last edited by a moderator:
now THATS allot of copy and pasting :)

as you can see, i can only print to one page... how do i modify it for it to be able to print on multiple pages?

Note, that the TransactionDetails are only needed to be re-fired when there is multiple pages... i dont want the savings account details to be displayed again and again :( :(
 
Im having trouble with this exact same issue. Anyone have any ideas? It appears that the printer.newpage method no longer exists in vb.net.
 
Last edited by a moderator:
Well after fooling with it all day, my co-worker realized that to print multiple pages, you need to have a printdocument object PER page. Not sure if this is the way its supposed to be done, but it does work.
 
A good link, finally understand HasMorePages

Here is a link that might help. The idea of HasMorePages is to have the PrintPage method call itself over and over tell it is equal to false. This gives you multiple pages the problem is now you have write your PrintPage in a way to only print enough for one page and then remember where to pick up and start printing information on the next page. This implies a lot of variables that have to be stored to hold some kind of state about what page you are on and what you want displayed.

http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsPrinting.aspx
 
Back
Top