最近因為計畫的關係,花了些時間整理平常上課比較不會特別教的內容,
例如條碼的產生, 列印的問題, 我將.VB.NET列印的範例整理如下:
首先先產生相關物件如下圖
'printdocument包含所有列印所需要的資訊,
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString(Me.TextBox1.Text, TextBox1.Font, Brushes.Black, 100, 100)
e.Graphics.PageUnit = GraphicsUnit.Inch
e.Graphics.PageUnit = GraphicsUnit.Inch
End Sub
'列印按鈕
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDialog1.Document = PrintDocument1 'PrintDialog associate with PrintDocument.
If PrintDialog1.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
'預覽列印按鈕
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintPreviewDialog1.Document = PrintDocument1 'PrintPreviewDialog associate with PrintDocument.
PrintPreviewDialog1.ShowDialog() 'open the print preview
PrintPreviewDialog1.ShowDialog() 'open the print preview
End Sub
沒有留言:
張貼留言