I have written software that creates a text file, the text file contains colums of data. When I view and print the text file using notepad all the colums line up correctly. I am now trying to print the text file using a button on my form but every time I print it all the colums are no longer lined up :-(
This is the code that I'm using to do the print.
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim LinesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim strLine As String = Nothing
Dim printFont As Font = Me.lblFadeRate.Font
Dim myBrush As New SolidBrush(Color.Black)
'Work out the number of lines per page, using the MarginBounds.
LinesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
'Iterate over the string using the StringBuilder, printing each line.
strLine = MyStreamReader.ReadLine
While count < LinesPerPage
'Calculate the next line position based on the height on the font according
'to the printing device
yPosition = (topMargin + (count * printFont.GetHeight(e.Graphics)))
'draw the next line in the stream
e.Graphics.DrawString(strLine, printFont, myBrush, leftMargin, yPosition, New StringFormat())
count += 1
strLine = MyStreamReader.ReadLine
End While
'check to see if there is another page left to print
If MyStreamReader.EndOfStream = False Then
e.HasMorePages = True
Else
e.HasMorePages = False
MyStreamReader.Close() 'Close stream reader
End If
End Sub
Am I missing a setting somewhere???
Thanks for any help you can give me
Simon