Dim txt1 As String = e.Form.Controls("TextBox1").Text '定义变量,用于手动输入打印数量
'Dim cmb1 As String = e.Form.Controls("ComboBox1").Text '定义变量,用于手动选择打印机
Dim doc As New PrintDoc
doc.PageSetting.Width = 50 '纸张宽度为200毫米
doc.PageSetting.Height = 30 '纸张高度为170毫米
DoC.PageSetting.LeftMargin = 1 '设置左侧边距为2毫米
DoC.PageSetting.RightMargin = 1 '设置右侧边距为2毫米
DoC.PageSetting.TopMargin = 1 '设置顶部边距为2毫米
Doc.PageSetting.BottomMargin = 1 '底部边距未1毫米
Doc.Style.TextAlignHorz = prt.AlignVertEnum.Center '垂直居中
DoC.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
'DoC.Style.TextAlignHorz = prt.AlignHorzEnum.Right '右对齐
doc.PageSetting.Landscape = True '横向打印
doc.AutoRotate = False '如果纸张的宽度超过高度,要加上这行代码
Dim rg As prt.RenderGraphics
Dim Bar As New BarCodeBuilder
Bar.Symbology = Barpro.Symbology.Code128
Bar.BarWidth = 0.3 '窄条宽度
Bar.BarRatio = 2.3 '设定宽窄比例
Bar.BarHeight = 12 '设定条码高度
Bar.QuietZoneWidth = 2 '静区宽度
Dim t As Table = Tables("XX条码表") '指定数据来源表
Dim ra As prt.RenderArea
For i As Integer = t.TopPosition To t.BottomPosition
Dim r As Row = t.Rows(i)
For j As Integer = 0 To val(txt1) - 1 '指定每行打印数量
If j Mod 3 = 0 Then
ra = new prt.RenderArea
Doc.Body.Children.Add(ra)
End If
bar.Code = r("XX条码") '指定条码数据来源列
Bar.QuietZoneWidth = 2
Bar.CodeAlignment = Barpro.Alignment.BelowJustify
Bar.Text = r("机构") '指定条码上方文本说明
Bar.TextFont = New Font("宋体",9,FontStyle.Bold) '定义说明文本字体及字号
Bar.TextAlignment = Barpro.Alignment.AboveLeft
rg = new prt.RenderGraphics
bar.DrawOnCanvas(rg.Graphics,0,0,1)
rg.Stacking = prt.StackingRulesEnum.InlineLeftToRight '设置容器中对象的排列方式
rg.Style.TextAlignHorz = prt.AlignVertEnum.Center '垂直居中
' rg.Style.Spacing.Bottom = 1
' rg.Style.Spacing.Right = 1 '设置右间间隔毫米
' rg.Style.Spacing.Left = 1 '左边距
rg.Style.TextAlignHorz = prt.AlignVertEnum.Center '垂直居中
rg.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
' rg.Style.TextAlignHorz = prt.AlignHorzEnum.Right '右对齐
ra.Stacking = prt.StackingRulesEnum.InlineLeftToRight '设置容器中对象的排列方式
ra.Style.TextAlignHorz = prt.AlignVertEnum.Center '垂直居中
ra.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
' ra.Style.Spacing.ALL = 1 '设置下间隔为3毫米
' ra.Style.Spacing.Bottom = 2 '设置下间隔为3毫米
' ra.Style.Spacing.Right = 10 '设置右间间隔毫米
' ra.Style.Spacing.Left = 3 '左边距
ra.Children.Add(rg)
Next
Next
Doc.PrinterName =" ZDesigner GK888t" '指定打印机
'Doc.Preview() '打印预览
Doc.Print '直接打印
上述代码单个打印(只选择1行)可以,连续打印(选择2行以上)时,第一张合适,打印第二张时打印机红灯、停止。求老师指点!