Start New Discussion within our Software Development Community

Hello,
As mentioned in the title I wanted to generate a data report and found this bit of code on microsoft page.

http://code.msdn.microsoft.com/vstudio/VBWinFormPrinting-ca19810f

Hoping Im correct,

Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim f As Font = New Font("Vanada", 12)
Dim br As SolidBrush = New SolidBrush(Color.Black)
Dim p As Pen = New Pen(Color.Black)
e.Graphics.DrawString("This is a text.", f, br, 50, 50)
e.Graphics.DrawRectangle(p, 50, 100, 300, 150)

[ Is this the place to Bind the elements from textbox on to the print page? ]
[ If so how is it done? ]

End Sub

For ex:

http://i45.tinypic.com/2lvtdi.png

First I search an employee and the textboxes are populated. Then when I hit the print button, the labels and the data in the textboxes should appear on the print page.

Guess I have specified my problem correctly.

Thank You :)

You could do something like the following:

e.Graphics.DrawString(TextBox1.Text,f,br,50,50)

If you wanted to pull them in from a dataset, you could do something like this:

Dim da As New OleDBDataAdapter("SELECT * FROM myTable",myCon)
Dim ds As New DataSet

da.Fill(ds,"MyTable")

If IsNothing(ds.Tables("MyTable")) = False And ds.Tables("MyTable").Rows.Count > 0 Then
   For i = 0 to ds.Tables("MyTable").Rows.Count - 1
       With ds.Tables("MyTable")
           e.Graphics.DrawString(.Rows(i)("MyColumn1"),f,br,50,50)
           'Just Remember to Increase the Y on the DrawString so that you are not writing everything in one spot.   
       End With
   Next
End If
This article has been dead for over six months. Start a new discussion instead.