Jad Jad - 7 months ago 11
Vb.net Question

Print textbox values to a table on printdocument

I need to print a document containing texts and tables. I'm ok with printing the text but i have searched alot how to print a table and I found nothing. I want to put values from the textboxes in cells on the printed table.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
DirectCast(PrintPreviewDialog1, Form).WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim printtext As String = vbCrLf + vbCrLf + vbCrLf + _
"File Number : " + TextBox1.Text + vbCrLf + vbCrLf + _
"Company Name : " + TextBox2.Text + vbCrLf + vbCrLf + _
"Description : " + TextBox3.Text + vbCrLf + vbCrLf
' Do something e.g.
e.Graphics.DrawString(printtext, New Font("Arial", 12, FontStyle.Bold), _
Brushes.Black, 10, 10)
e.HasMorePages = False

End Sub


Any help is appreciated. Cheers

Answer

You can use e.Graphics.DrawRectangle with e.Graphics.DrawLine

You may also find these articles useful:

DataGridView Printing

Printing Tabular Data