谢谢 按老师指导:如果当前二维码打印机不存在 还是会提示如图 开始打印……及对应错误代码
麻烦老师继续指导下 谢谢!不想弹出开始打印……
详细错误代码:
错误的事件名称自定义函数,二维码打印
System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.ComponentModel.Win32Exception: 已删除指定的打印机。
在 System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
在 System.Drawing.Printing.PrintController.Print(PrintDocument document)
在 System.Drawing.Printing.PrintDocument.Print()
在 C1.C1Preview.C1PrintManager.Print(PrinterSettings printerSettings, PageSettings defaultPageSettings)
在 Foxtable.PrintDoc.Print()
在 UserCode.Ame3oeOl4rui6jRif(Object[] Args)
--- 内部异常堆栈跟踪的结尾 ---
在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 Foxtable.UserFunctions.Execute(String Name, Object[] Args)
2022-10-10 00:09:39
当前代码如下:
Dim guid As String = Args(0)
'Dim erweimadayinji As String = Args(1)
Dim cmd As new SQLCommand
cmd.Conne ctionN ame="主数据源"
cmd.Com mand Text = "sele ct * from {SYS_二维码参数及标签打印机设置} " 'where 二维码打印机='" & erweimadayinji & "'"
Dim dt11 As DataTable = cmd.ExecuteReader()
Dim dr11 As DataRow = dt11.DataRows(0)
output.show(1)
Dim fl As String
If dt11.datarows.count > 0 Then '如果有数据,就操作,反之不操作
output.show(dr11("纸张宽度"))
Dim doc As New PrintDoc() '定义一个报表
doc.PageSetting.Width = cint(dr11("纸张宽度")) '纸张宽度
doc.PageSetting.Height = cint(dr11("纸张高度")) '纸张高度
Doc.PrinterName = dr11("二维码打印机") '设定打印机为当前选择的打印机'
output.show(dr11("二维码打印机"))
Dim img As prt.RenderImage '定义一个图像'
Dim Bar As New BarCodeBuilder
Bar.Symbology = Barpro.Symbology.QRCode
Bar.BarWidth = cint(dr11("二维码宽度"))
Bar.BarHeight = cint(dr11("二维码高度"))
Bar.QuietZoneWidth = cint(dr11("二维码静区"))
Bar.QRCodeModuleSize = dr11("模组尺寸")
Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight
'For Each p As String In InstalledPrinters
If InstalledPrinters.Contains(dr11("二维码打印机")) Then
Output.Show(InstalledPrinters.Contains(dr11("二维码打印机")))
cmd.Comm andText = "sel ect * from {XX_设备台账} where guid='" & guid & "' "
Dim dt111 As DataTable = cmd.ExecuteReader()
Dim dr111 As DataRow = dt111.DataRows(0)
If dt111.datarows.count > 0 Then
fl = ProjectPath & "Reports\" & dr111("设备编号") & "二维码.jpg"
Bar.Code = dr111("设备编号")
img = new prt.RenderImage
img.Image = bar.GetImage
img.X=cint(dr11("图片x"))
img.y=cint(dr11("图片Y"))
img.Width = cint(dr11("图片高度")) '宽度等于页面宽度
img.Height = cint(dr11("图片宽度"))''高度由图片大小自动决定
Doc.Body.Children.Add(img)
doc.Print
End If
End If
'Next
End If
[此贴子已经被作者于2022/10/10 0:09:43编辑过]