Recycling code to print more pages

PAffiliates

Member
Joined
Aug 15, 2007
Messages
10
Programming Experience
Beginner
Hello,

My question is somewhat complicated. It is as follows:

I am working on a program that prints labels 4 on a page. I am using an Array of a Structure to capture the data from the user. I need to use the same code for the placement in the PrintDocument_PrintPage handler. The way I have it set up now is

If "the number of labels" <= 4 Then

It prints out the labels where I have them placed

ElseIF "the number of labels" > 4 Then

I tried using a Do Until loop to print the first four, then increment the l1Int - l4Int(array index #) by 4
to print the second batch of labels and so on until the partNumberString is = "" (which means that there is no more labels)
I have attempted to use e.hasmorepages = True with the incremented l1Int - l4Int to print out multiple pages with the same structure, but different data. I'm trying to keep this dynamic so that the user can enter in as many labels as they wish without having to worry about whether they will print or not. I can't get it to print more than the first page of labels. The second page is blank. Is there really a way to recycle this code and get the result that I am seeking?

Any help would be most appreciated!!!

Thank you!!
 
Here's a HasMorePages example that prints one array item each page:
VB.NET:
Private data() As String = {"page one", "page two", "page three"}
Private counter As Integer

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

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
    e.Graphics.DrawString(data(counter), Me.Font, Brushes.Blue, 100, 100)
    counter += 1
    If counter < data.Length Then e.HasMorePages = True
End Sub
 
Thank you so much for your help once again John! I was able to take your example and understand that e.HasMorePages actually acts like a loop when it recalls the PrintDocument. Very fascinating stuff! I've learned a lot through all this and am very glad that there are people like you who take time out to help beginners. Thanks again!!!
 
Back
Top