Multi pages printing

yulyos

Well-known member
Joined
Jun 4, 2004
Messages
67
Location
Israel
Programming Experience
5-10
Hi,

I want to print the value of N in Multi pages printing.
Example:
First page from 1 to 10
Second page from 11 to 20
And so on until 100, it will be 10 pages.
I tried with "e.HasMorePages = True", but without success.

Thanks in advance

My code:
VB.NET:
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim drawFont As New Font("Microsoft Sans Serif", 8, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)
        '
        Dim x As Single = e.MarginBounds.Left
        Dim y As Single = e.PageBounds.Top
        '
        For N As Integer = 1 To 100
            e.Graphics.DrawString(N, drawFont, drawBrush, x + 5, y + 16)
            y += 16
        Next
    End Sub
 
To print to 100 :-

VB.NET:
    Private intDisplayNumber As Int32

    Private Sub PrintDocument1_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
        intPageNumber = 0
        intDisplayNumber = 0
    End Sub


    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim drawFont As New Font("Microsoft Sans Serif", 8, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)

        Dim x As Single = e.MarginBounds.Left
        Dim y As Single = e.PageBounds.Top
        '
        For N As Integer = 1 To 10
            intDisplayNumber += 1
            e.Graphics.DrawString(intDisplayNumber.ToString, drawFont, drawBrush, x + 5, y + 16)
            y += 16
        Next

        If intDisplayNumber < 100 Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub


To print 10 pages :-

VB.NET:
    Private intTotalPages As Int32
    Private intPageNumber As Int32

    Private Sub PrintDocument1_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
        intPageNumber = 0
        intTotalPages = 10
    End Sub


    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage

        intPageNumber += 1

        Dim drawFont As New Font("Microsoft Sans Serif", 8, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)

        Dim x As Single = e.MarginBounds.Left
        Dim y As Single = e.PageBounds.Top
        '
        For N As Integer = ((intPageNumber - 1) * 10) + 1 To ((intPageNumber - 1) * 10) + 10
            e.Graphics.DrawString(N, drawFont, drawBrush, x + 5, y + 16)
            y += 16
        Next

        If intPageNumber < intTotalPages Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub
 
Back
Top