Kemudian klik dua kali pada komponen PrintDocument1, tambahkan kode program yang berisi apa yang mau kita tulis ke printer, bisa pula menggambar garis, lingkaran, kotak dsb sesuai koordinat yang kita tentukan :
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString("Halo, Test Print", New Font("Arial", 10), Brushes.Black, 10, 10)
'e.Graphics.DrawRectangle(..)
'e.Graphics.DrawEllipse(..)
'e.Graphics.DrawLine(..)
End Sub
Kemudian dari tombol panggil PrintDocument1 untuk mulai mengeprint, dapat dilakukan dahulu pengubahan setting jumlah copy, orientasi dll :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'PrintDocument1.PrinterSettings.Copies = 2
PrintDocument1.Print()
End Sub
Kode program selengkapnya :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'PrintDocument1.PrinterSettings.Copies = 2
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString("Halo, Test Print", New Font("Arial", 10), Brushes.Black, 10, 10)
'e.Graphics.DrawRectangle(..)
'e.Graphics.DrawEllipse(..)
'e.Graphics.DrawLine(..)
End Sub
End Class