打印多个文档时,第一个文档转到错误的打印机

时间:2013-12-27 18:37:24

标签: .net vb.net printing

我必须以编程方式创建和打印多个文档(标签)。我的代码正确创建并打印除第一个标签之外的每个标签;它被发送到默认打印机,而不是指定的打印机。有谁知道解决这个问题吗?

Do While ....
txt = sometext
PrintDocument1.Print()
Loop

Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim prFont As New Font("Arial Narrow", 19, FontStyle.Bold)
Dim format As New StringFormat
format.Alignment = StringAlignment.Center

e.PageSettings.PrinterSettings.PrinterName = "\\TLN-CESDC2\TLN2-41-LABEL"
e.PageSettings.Margins.Bottom = 20
e.PageSettings.Margins.Left = 0
e.PageSettings.Margins.Right = 0
e.PageSettings.Margins.Top = 20
e.Graphics.DrawString(txt, prFont, Brushes.Black, 200, 15, format)
End Sub

1 个答案:

答案 0 :(得分:2)

在开始循环之前尝试设置打印机:

PrintDocument1.PrinterSettings.PrinterName = "\\TLN-CESDC2\TLN2-41-LABEL"
Do While ....
  txt = sometext
  PrintDocument1.Print()
Loop

请参阅PrintDocument.PrinterSettings Property