Results 1 to 3 of 3

Thread: [2005/2008] Multi pages printing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    [2005/2008] Multi pages printing

    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:
    Code:
        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

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2005/2008] Multi pages printing

    The "PrintPage" event is raised once for every page printed - therefore your loop needs to be changed to only do the next 10 rows, rather than the full 100 each time the event is called.

    To do this you need a _currentrow variable outside of the event handler and update it in the event handler e.g.:

    Code:
        Dim _currentRow As Integer = 1
    
        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 = _currentRow  To _currentRow + 10
                e.Graphics.DrawString(N, drawFont, drawBrush, x + 5, y + 16)
                y += 16
            Next
    
            _currentRow  = _currentRow  + 10 'we printed 10 rows on this page
     
            If _currentRow  < 100 Then
              e.HasMorepages = True
            End If
        End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: [2005/2008] Multi pages printing

    Hi,

    Thank you, it's working good.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width