Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Object Equivalent in dot NET ?

Status
Not open for further replies.

HaworthBantam

Programmer
Jan 31, 2002
132
0
0
GB
Folks,

I've been looking at this for a while now and I appear to be going round in circles, so any help would be greatly received.

I'm looking to print records from a data table. My VB6 code is:

Public Sub PrintRecord()

Dim strMySQL As String
Dim dbTest As Database
Dim rsTest As Recordset
Dim lngPayID As Long
Dim strTitle As String
Dim strForename As String
Dim strSurname As String
Dim lngX As Long, lngY As Long

strMySQL = "SELECT * FROM tblStaffPayIDs"
Set dbTest = OpenDatabase("C:\BDApps\Test\Test.mdb")
Set rsTest = dbTest.OpenRecordset(strMySQL)

'X and Y coordinates are set in "twips" - 1440 twips per inch (approx).

lngY = 400 'Set the Y coordinate to zero - this sets the vertical position.

Printer.FontSize = 12 'Set the font size
Printer.CurrentX = 1440 'Set the horizontal position.
Printer.CurrentY = lngY 'Set the vertical position
Printer.Print "Pay ID" 'Print the "header".
Printer.CurrentX = 2880 'Set the horizontal position.
Printer.CurrentY = lngY 'Set the vertical position.
Printer.Print "Name" 'Print the "header"

Printer.FontSize = 10 'Set the font size for the data.
With rsTest
.MoveFirst
Do Until .EOF 'Cycle through the data to print each record.
lngY = lngY + 400 'Set the vertical position of the next record.
lngPayID = !PayID
strTitle = !Title
strForename = !Forename
strSurname = !Surname
Printer.CurrentX = 1440
Printer.CurrentY = lngY
Printer.Print lngPayID
Printer.CurrentX = 2880 'Set the horizontal position of the name data.
Printer.CurrentY = lngY
Printer.Print strTitle & " " & strForename & " " & strSurname
.MoveNext 'Move to the next record
Loop
End With

Printer.EndDoc 'Print the document.

End Sub

This is pretty straight forward in VB6. However, I cannot work out how to do the exact same thing using dot NET.

Can any kind soul put me on the right track.....?

Thanks.
 
Drag and drop one or more on the form, double click it and write there you code to print. To design (anything; text, graphics etc) use the e.Graphics.{...}
For a short cut... rather than writing 'e.grapgics.something' all the time:
dim g as graphics = e.graphics, and use the 'g' variable instead


Hope tis helps
 
Thanks for the advice guys.

Because of the urgency of the project I'm working on, I think I'm going to write this current project in VB6. And then look at rewriting in dot NET at a later date, when time isn't too much of a factor.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top