Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Sub printbarcode(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal barcodenum As ArrayList, ByVal barcodeqty As ArrayList, ByVal barcodeprz As ArrayList, ByVal barcodeart As ArrayList, ByVal barcodesize As ArrayList, ByVal barcodecolor As ArrayList)
        'Public Sub printbarcode(ByVal barcodenum As ArrayList, ByVal barcodeqty As ArrayList, ByVal barcodeprz As ArrayList, ByVal barcodeart As ArrayList, ByVal barcodesize As ArrayList, ByVal barcodecolor As ArrayList)
        Dim x1 As Integer = 0
        Dim y1 As Integer = -4
        Dim x2 As Integer = 28
        Dim y2 As Integer = 12
        Dim x3 As Integer = 24
        Dim y3 As Integer = -4
        Dim cnt As Integer = 0
        Dim i As Integer
        e.Graphics.PageUnit = GraphicsUnit.Millimeter
        e.Graphics.PageScale = 1
        Dim qty1 As Integer = 0
        Dim qty As Integer = 0
        Dim j, k As Integer
        k = 0
        For j = 0 To barcodeqty.Count - 1
            qty = qty + Convert.ToInt32(barcodeqty(j))
        Next
        j = 0
        Dim charCount As Integer = 0
        Dim lineCount As Integer = 0



        'Dim pageheight As Integer = e.MarginBounds.Height


        qty1 = Convert.ToInt32(barcodeqty(j))
        For i = 0 To qty - 1
            If (i = qty1 And qty > 0) Then
                j = j + 1
                qty1 = qty1 + Convert.ToInt32(barcodeqty(j))
                ' i = 0
            End If
            CreateEan13(barcodenum(j))
            'printme(barcodenum(j), e.Graphics)

            ean13.Scale = CType(Convert.ToDecimal("1.4"), Single)
            If ((k Mod 2) = 0 And k > 0) Then
                y = y + 26
                x = 2.8
            End If

            e.Graphics.DrawString("Bag Zone", New System.Drawing.Font("Arial", 8, FontStyle.Bold), New System.Drawing.SolidBrush(System.Drawing.Color.Red), New System.Drawing.Point(x1 + x, y1 + y))
            e.Graphics.DrawString(barcodesize(j) + " / " + barcodeart(j), New System.Drawing.Font("Arial", 7), New System.Drawing.SolidBrush(System.Drawing.Color.Black), New System.Drawing.Point(x3 + x, y3 + y))
            ean13.DrawEan13Barcode(e.Graphics, New System.Drawing.Point(x, y))
            e.Graphics.DrawString("Colour:" + barcodecolor(j) + " ", New System.Drawing.Font("Arial", 7), New System.Drawing.SolidBrush(System.Drawing.Color.Black), New System.Drawing.Point(x1 + x, y2 + y))
            e.Graphics.DrawString("MRP ` " + barcodeprz(j) + "/-", New System.Drawing.Font("Rupee Foradian", 9, FontStyle.Bold), New System.Drawing.SolidBrush(System.Drawing.Color.Black), New System.Drawing.Point(x2 + x, y2 + y))
            x = x + 50
            If (qty = 0) Then
                Exit For
            Else
                qty = qty - 1
            End If
            k = k + 1




        Next


        e.HasMorePages = False
        e.Graphics.Dispose()





    End Sub
Posted
Comments
Richard MacCutchan 4-Mar-14 4:49am    
e.HasMorePages = False. Set this to True if more pages are required.

1 solution

The printbarcode sub gets called once per page until you set e.HasMorePages to True.

This means that any variables you initialise in this subroutine will be re-initialised every time a new page is called. I would recommend moving any "how much have I printed so far" variables outside of the printbarcode.

Check out the article An absolute beginner's guide to printing in .NET[^] for more info.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900