VB2013 Code does not recognize hieght of a label

Hello Experts,
The following vb2013 code prints ONE label ans stays right where the last line was printed,
How can I make it jump to the next label ?
not leave a whole blank label, but just go to next label.

Right now its not leaving a blank label, just stays in the las printed line and does not jump to the beggining of the next label. which is what I need order to send the next label with different data.



Public Class Form1

    'Button1 starts printing of a single-page document with barcode.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim pd As New Printing.PrintDocument
        pd.PrinterSettings.PrinterName = "ZDesigner GC420d (EPL)" '-- Uncomment this to select a specific printer.

        AddHandler pd.PrintPage, AddressOf PrintHandler
        RemoveHandler pd.PrintPage, AddressOf PrintHandler
    End Sub

    'This Sub constructs a printable page.
    Private Sub PrintHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        Dim barcode = AxStrokeScribe1 'This name is assigned to the barcode ActiveX by default.'To check which name the ActiveX actually has, select the ActiveX, press Alt-Enter and look for the Design group in the Properties box.
        barcode.Alphabet = enumAlphabet.CODE128 'Change this to produce barcode of the desired type.
        barcode.CtlText = "1234ABCD" 'This text will be stored in the barcode.

        Dim img As Image
        img = barcode.GetPictureHandle(enumFormats.EMF, 30, 15) 'Generates a barcode picture, 50x30mm.
        If barcode.Error Then
        End If

        Dim ag = args.Graphics

        ag.PageUnit = GraphicsUnit.Millimeter
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 1) 'A text label near the barcode
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 4)
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 7)
        ag.DrawImage(img, 1, 10) 'Position of the left-top corner of the barcode relatively to the left-top corner of the page (millimeters).

        args.HasMorePages = False 'We print only one page each time the Button1 is pressed.
    End Sub
End Class

Open in new window

RGuillermoProject ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
Do you want to print many copies of the same label, or print different information on each label?

Are you printing on label sheets that have many columns or on a 1 column label printer?
RGuillermoProject ManagerAuthor Commented:
I am printing in a one column label zebra printe GC420d
and most of the time I need to print diferente labels.
But at the end of the month I may need to repeat a few labels almost a hundres copies.
Jacques Bourgeois (James Burger)PresidentCommented:
I am kind in a hurry right now (Saturday evening here in the Montreal area), so I do not have time to give you sample code, but here is the basic rundown.

args.HasMorePages = False does not really mean a page, it means that you have nothing else to print and it stops the printing. Usually, you set it to True when a whole page has been printed. This triggers the event again, and you continue printing on the following page from where you left on the previous run of the event.

It's not evident from what I see with a quick search, but the GC420d looks like one of these printers that have a continuous feed of labels from a roll. When you print a series of labels such a printer, you forget about the notion of page. The "page" is a single label if you print them one by on, your whole series if you print many of them in the same run.

If you print one label at a time, add an extra DrawString with a space as text, specifying a Y parameter that will have the right value to bring you to the beginning of the following label before you set HasMorePages to False. You will then be ready for your next label.

If you print a series of labels, the trick is to first have the data ready in a variable declared at the class/form/module level so that it is available in the event. If you need to print different labels, store the data in a collection or array variable.

You then enclose your series of DrawString + DrawImage in a loop. Each run in the loop will print one label. And instead of using fixed values for the vertical position (1, 4, 7 and 10) , use multiples of the loop counter multiplied by the height of 1 label plus the space between labels. If you loop with something like For x=0 to 10, then use 1+14*x, 4+14*x, 7+14*x and 10+14*x). You will have to try with different values for the 14. It needs to be adjusted for the type of labels that you use.

Because the loop runs before the HasMorePages=False command, it will continue printing as long as you loop. And since you are increasing the Y position in each loop, it will just go lower down on the ribbon that holds the labels.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RGuillermoProject ManagerAuthor Commented:
thank you Jacques,
That was clear enough
If you have time send me a Little code just in case,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.