Kod:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' önizleme
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Dim i As Integer = 0
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim format As New StringFormat
format.Alignment = StringAlignment.Center
Dim yazi_fontu As New System.Drawing.Font("Arial", 10, FontStyle.Regular)
Dim satir As Integer = 1
Dim top As Integer = 50
Dim satiryuksekligi As Integer = yazi_fontu.Height
e.Graphics.DrawString("Başlık", New Font("arial", 12, FontStyle.Bold), Brushes.Black, New RectangleF(0, top, e.PageSettings.PrintableArea.Width, e.PageSettings.PrintableArea.Height), format)
While i < DataGridView1.RowCount
e.Graphics.DrawString(DataGridView1.Item(0, i).Value.ToString, yazi_fontu, Brushes.Black, 100, top + satir * satiryuksekligi)
e.Graphics.DrawString(DataGridView1.Item(1, i).Value.ToString, yazi_fontu, Brushes.Black, 100 + 40, top + satir * satiryuksekligi)
e.Graphics.DrawString(DataGridView1.Item(2, i).Value.ToString, yazi_fontu, Brushes.Black, 100 + 90, top + satir * satiryuksekligi)
e.Graphics.DrawString(DataGridView1.Item(3, i).Value.ToString, yazi_fontu, Brushes.Black, 100 + 140, top + satir * satiryuksekligi)
e.Graphics.DrawString(DataGridView1.Item(4, i).Value.ToString, yazi_fontu, Brushes.Black, 100 + 200, top + satir * satiryuksekligi)
satir = satir + 1
i = i + 1
If satir = 20 Then
satir = 1
Exit While
End If
End While
If i < DataGridView1.RowCount Then e.HasMorePages = True Else e.HasMorePages = False : i = 0 : satir = 1
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'yazdırma
PrintDocument1.Print()
End Sub
ayrıca printdocument ve printpreviewdialog kontrolünü toolboxtan form eklemelisiniz.