例如,我有一个标签可以打印,如下例所示,现在如果我要制作3份副本,如何在我正在打印的标签中的某处打印副本号?
示例代码:
Private Sub btnPrintProcLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintProcLabel.Click
If ValidateData() Then
AddHandler PrintDocument1.PrintPage, AddressOf PrintProcLabel
Try
PrintDocument1.PrinterSettings.PrinterName = SinglePrinter.PrinterSettings.PrinterName
PrintDocument1.PrinterSettings.Copies = CInt(txtCopies.Text)
PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Public Sub PrintProcLabel(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim g As Graphics = e.Graphics
Dim br As Brush = New SolidBrush(Color.Black)
Dim pn As Pen = New Pen(br)
g.DrawString(Today.Month & "/" & Today.Day & "/" & Today.Year, Arial, br, 250, 3)
End Sub
答案 0 :(得分:1)
PrintDocument1.PrinterSettings.Copies = CInt(txtCopies.Text)
告诉打印机驱动程序生成副本,它们都是相同的。如果你想给它们编号,那么你需要自己创建“副本”。它们不再是真正的副本,因为它们都会略有不同。只需使用一个计数器重复调用Print()方法,该计数器的值是PrintPage事件处理程序中的DrawString()。