2013-02-01 57 views
0

打印副本號碼例如,我有一個標籤要打印,如下面的示例,現在如果我想打印3份副本,如何打印副本號碼在我打印的標籤中的某處?如何使用system.drawing.printing.printdocument vb.net

示例代碼:

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 

回答

1
PrintDocument1.PrinterSettings.Copies = CInt(txtCopies.Text) 

這告訴打印機驅動程序生成的副本,他們都將是相同的。如果你想給它們編號,那麼你需要自己創建「拷貝」。他們不再是真正的副本,因爲他們都會有所不同。只需使用PrintPage事件處理函數中的DrawString()值的計數器重複調用Print()方法即可。

+0

是的,我想迭代的次數與'txtCopies.Text'中指定的次數一樣多,所以我可以每次都有特定的拷貝數。我認爲沒有其他辦法可以做到這一點。 – Somebody