944,185 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2094
  • VB.NET RSS
Jul 31st, 2007
0

Printing problem

Expand Post »
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.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  2.  
  3. Dim LinesPerPage As Single = 0
  4. Dim yPosition As Single = 0
  5. Dim count As Integer = 0
  6. Dim leftMargin As Single = e.MarginBounds.Left
  7. Dim topMargin As Single = e.MarginBounds.Top
  8. Dim strLine As String = Nothing
  9. Dim printFont As Font = Me.lblFadeRate.Font
  10. Dim myBrush As New SolidBrush(Color.Black)
  11.  
  12. 'Work out the number of lines per page, using the MarginBounds.
  13. LinesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
  14.  
  15. 'Iterate over the string using the StringBuilder, printing each line.
  16. strLine = MyStreamReader.ReadLine
  17. While count < LinesPerPage
  18. 'Calculate the next line position based on the height on the font according
  19. 'to the printing device
  20. yPosition = (topMargin + (count * printFont.GetHeight(e.Graphics)))
  21.  
  22. 'draw the next line in the stream
  23. e.Graphics.DrawString(strLine, printFont, myBrush, leftMargin, yPosition, New StringFormat())
  24. count += 1
  25. strLine = MyStreamReader.ReadLine
  26. End While
  27.  
  28. 'check to see if there is another page left to print
  29. If MyStreamReader.EndOfStream = False Then
  30. e.HasMorePages = True
  31. Else
  32. e.HasMorePages = False
  33. MyStreamReader.Close() 'Close stream reader
  34. End If
  35. End Sub

Am I missing a setting somewhere???


Thanks for any help you can give me

Simon
Similar Threads
Reputation Points: 34
Solved Threads: 0
Light Poster
blondie.simon is offline Offline
27 posts
since Jul 2007
Jul 31st, 2007
0

Re: Printing problem

Are you printing from the same system on which your code resides.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Jul 31st, 2007
0

Re: Printing problem

Yes
Reputation Points: 34
Solved Threads: 0
Light Poster
blondie.simon is offline Offline
27 posts
since Jul 2007
Jul 31st, 2007
0

Re: Printing problem

Are you printing from the same system on which your code resides.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Jul 31st, 2007
0

Re: Printing problem

Are yo sure the printer is not a network printer and the font of notepad is same every where.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Jul 31st, 2007
0

Re: Printing problem

Hi Simon,

make the Font of the NotePad "Courier New", it is a UniDistant font (all fonts acquire same space on screen/media), ur texts will look like Columns..

REgards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 31st, 2007
0

Re: Printing problem

Click to Expand / Collapse  Quote originally posted by QVeen72 ...
Hi Simon,

make the Font of the NotePad "Courier New", it is a UniDistant font (all fonts acquire same space on screen/media), ur texts will look like Columns..

REgards
Veena

Thanks for that It worked a treat
Reputation Points: 34
Solved Threads: 0
Light Poster
blondie.simon is offline Offline
27 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Length of WAV
Next Thread in VB.NET Forum Timeline: basic operations..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC