- ' Place a button on the form (PrintPreview)
- ' PLace a textbox control on the form (TextData)
- Imports System.Drawing
- Imports System.Drawing.Printing
- Public Class Form1
- Private Doc As New PrintDocument()
- Private Sub PrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreview.Click
- Dim ppDlg As New PrintPreviewDialog()
- ppDlg.Document = Doc
- ppDlg.Show()
- AddHandler Doc.PrintPage, AddressOf Print_PrintPage
- End Sub
- Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
- Dim g As Graphics = e.Graphics
- Dim Brush As New SolidBrush(Color.Black)
- g.DrawString(Me.TextData.Text, New Font("arial", 9), Brush, 10, 10)
- End Sub
- End Class
Simple PrintDocument Example In VB.NET
This code snippet shows you how to use the PrintDocument class to print documents. It uses the PrintPreviewDialog to show the preview of the document and a button to print the document.
No comments:
Post a Comment