Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When i used for loop to print database table and that data is of two pages, then i use e.hasmorepages=true. but e.hasmorepages is not stop.Means continue.
The code is below:

VB
Dim x As Int32 = e.MarginBounds.Left
        Dim y As Int32 = e.MarginBounds.Top
        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
        fmt.LineAlignment = StringAlignment.Center
        fmt.Alignment = StringAlignment.Center
        Dim rec As Rectangle
        Dim mrow As Integer = 0
        Dim h As Int32 = 0
        Dim i As Int32
        If newpage Then
            'Dim image As Image
            'e.Graphics.DrawImage(image, 20, 20, 70, 50)
            

        End If
        For i = mrow To tbl.Rows.Count - 1
            x = e.MarginBounds.Left
            h = 0
            x = e.MarginBounds.Left
            For j As Integer = 0 To tbl.Columns.Count - 1
                rec = New Rectangle(x, y, 60, 30)
                e.Graphics.DrawRectangle(Pens.Black, rec)
                e.Graphics.DrawString(tbl.Rows(i)(j).ToString, rfont, Brushes.Black, rec, fmt)
                x += rec.Width
                h = Math.Max(h, rec.Height)
            Next
            y += h
            mrow += 1
            If y + h > e.MarginBounds.Bottom Then
                e.HasMorePages = True
                'mrow -= 1
                newpage = True
                Return
            Else
                newpage = False
            End If
            
        Next


What I have tried:

I have searched for many blogs but this issue is not resolved. Kindly, guide me to solve this issue
Posted
Updated 26-Jul-21 2:31am
v2
Comments
CHill60 26-Jul-21 7:45am    
Your problem is not clear. Can you explain it in more detail

1 solution

What HasMorePages does is tells the PrintDocument that you are finished, or not.
If you aren't (HasMorePages == True) then PrintPage gets called again so you can generate the next page. It doesn't "break" the page immediately you set it's value - so you set it, save where you are in the data input, and exit the method.
The framework then calls it again ready for the next page of data - so you pick up where you left off with a new page.
 
Share this answer
 
Comments
Maciej Los 27-Jul-21 2:54am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900