question

ahmedAlie-8738 avatar image
0 Votes"
ahmedAlie-8738 asked LesHay-2099 answered

print more than one page

hi

I want to print a variable text string in more than one page.
Where I add a number and a repeating alliance to define the number and I want to print to the end of the group and the ring of numbers used.
I used the following code and it does what is needed if the printer is A4
.The code does not work at all when using a barcode printer (paper size 40*25). What is the problem when the printer is different?
Pages keep coming back indefinitely and the repetition doesn't stop forever.

'PrintDocument event

  Private printLine As Integer = 0

    Dim startX As Integer = e.MarginBounds.Left
         Dim startY As Integer = e.MarginBounds.Top
    
         Do While printLine < 10
             If startY + PictureBox1.Height > e.MarginBounds.Bottom Then
                 e.HasMorePages = True
                 Exit Do
             End If
             e.Graphics.DrawString(" good " & printLine.ToString, Me.Font,
                                   Brushes.Black, startX, startY)
             startY += PictureBox1.Height
             printLine += 1
         Loop

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LesHay-2099 avatar image
1 Vote"
LesHay-2099 answered

Hi

Here is some code that seems to do what you ask.
I don't have a Priner so am using the inbuilt XPS printer with a user pagesize (40 x 25).
With this code I get 10 pages as expected.

 Option Strict On
 Option Explicit On
 Imports System.Drawing.Printing
    
 Public Class Form1
     Private printLine As Integer = 1
     Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    
         With PrintDocument1.DefaultPageSettings
             .PaperSize = New PaperSize("Custom Paper Size", 40, 25)
             .Margins.Top = 1
             .Margins.Bottom = 1
             .Margins.Left = 1
             .Margins.Right = 1
         End With
     End Sub
     Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As PrintEventArgs) Handles PrintDocument1.BeginPrint
         printLine = 1
     End Sub
     Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    
         Dim startX As Integer = e.MarginBounds.Left
         Dim startY As Integer = e.MarginBounds.Top
         e.Graphics.DrawString(" good " & printLine.ToString, New Font("Arial", 7), Brushes.Black, startX, startY)
    
         If printLine < 10 Then
             e.HasMorePages = True
             printLine += 1
         End If
    
     End Sub
    
     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         ' PAGE SETTINGS
         PageSetupDialog1.ShowDialog()
     End Sub
     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
         ' DIRECT PRINT
         PrintDocument1.Print()
     End Sub
     Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
         ' PREVIEW
         With PrintPreviewDialog1
             .Size = New Size(850, 500)
             .PrintPreviewControl.Zoom = 6.0
             .ShowDialog()
         End With
     End Sub
     Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
         ' PRINT DIALOG
         With PrintDialog1
             .AllowSomePages = True
             .AllowCurrentPage = True
             .AllowSelection = True
             .AllowPrintToFile = True
             .ShowNetwork = True
         End With
         If PrintDialog1.ShowDialog() = DialogResult.OK Then
             PrintDocument1.Print()
         End If
     End Sub
 End Class
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.