我只打算打印第一页而不是其他页面。请帮我打印所有页面 [英] I am geeting print only First page not others pages. Please help me to print all the pages

查看:61
本文介绍了我只打算打印第一页而不是其他页面。请帮我打印所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公开  Sub  printbarcode( ByVal  sender  As  System。 Object  ByVal  e  As  System.Drawing.Printing.PrintPageEventArgs, ByVal  barcodenum 作为 ArrayList, ByVal  barcodeqty 作为 ArrayList, ByVal  barcodeprz 作为 ArrayList, ByVal  barcodeart 作为 ArrayList, ByVal  barcodesize 作为 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 作为 整数 = 0
Dim y1 作为 整数 = -4
Dim x2 As 整数 = 28
Dim y2 As 整数 = 12
Dim x3 作为 整数 = 24
Dim y3 作为 整数 = -4
Dim cnt 作为 整数 = 0
Dim i 作为 整数
e.Graphics.PageUnit = GraphicsUnit.Millimeter
e.Graphics.PageScale = 1
Dim qty1 作为 整数 = 0
Dim qty 作为 整数 = 0
Dim j,k As Integer
k = 0
对于 j = 0 barcodeqty.Count - 1
qty = qty + Convert.ToInt32(barcodeqty (j))
下一步
j = 0
Dim charCount 作为 整数 = 0
Dim lineCount As 整数 = 0



' Dim pageheight As Integer = e.MarginBounds .Height


qty1 = Convert.ToInt32(barcodeqty(j))
对于 i = 0 数量 - 1
如果(i = qty1 qty> 0 然后
j = j + 1
qty1 = qty1 + Convert.ToInt32(barcodeqty(j))
' i = 0
结束 如果
CreateEan13(barcodenum(j) )
' printme(barcodenum(j),e.Graphics)

ean13.Scale = CType (Convert.ToDecimal( 1.4),
如果((k Mod 2 )= 0 k> 0 然后
y = y + 26
x = 2 8
结束 如果

e.Graphics.DrawString( Bag Zone System.Drawing.Font( < span class =code-string> Arial, 8 ,FontStyle.Bold), System.Drawing.SolidBrush(System.Drawing.Color.Red), New System.Drawing.Point(x1 + x,y1 + y))
e.Graphics.DrawString(barcodesize(j)+ / + barcodeart(j),< span class =code-keyword>新 System.Drawing.Font( Arial 7 ), System.Drawing.SolidBrush(System.Drawing.Color.Black), System.Drawing.Point(x3 + x,y3 + y ))
ean13.DrawEan13Barcode(e.Graphics, New System.Drawing.Point(x,y))
e.Graphics.DrawString( 颜色: + barcodecolor(j)+ System.Drawing.Font( Arial 7 ), System.Drawing.SolidBrush(System.Drawing.Color.Black), System.Drawing.Point(x1 + x,y2 + y))
e.Graphics.DrawString( MRP` + barcodeprz(j)+ / - System.Drawing.Font( Rupee Foradian 9 ,FontStyle.Bold), System.Drawing.SolidBrush (System.Drawing.Color.Black), System.Drawing.Point(x2 + x,y2 + y))
x = x + 50
如果(qty = 0 然后
退出 对于
其他
qty = qty - 1
结束 如果
k = k + 1




下一步


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





结束 Sub

解决方案

每个页面调用一次printbarcode子句,直到你将e.HasMorePages设置为True。



这意味着每次调用新页面时,您在此子例程中初始化的任何变量都将重新初始化。我建议在打印条码之外移动任何我到目前为止打印了多少变量。



查看文章绝对新手的.NET打印指南 [ ^ ]了解更多信息

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

解决方案

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.


这篇关于我只打算打印第一页而不是其他页面。请帮我打印所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆