|
-
Nov 26th, 2012, 04:00 PM
#1
Thread Starter
Frenzied Member
Printing Contents of RTB
I am using the following code to print some images, lables and now want to incorporate printing the contents of an RTB. The problem is is the user does NOT use the enter key to start a new line the contents print as one long line
I do not want to use PowerPacks printing thannks for any help
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim img1 As Image = PictureBox1.Image
Dim printArea1 As New RectangleF(1, 1, 5, 3.0) 'dimensions in inches
Dim img2 As Image = PictureBox2.Image
Dim printArea2 As New RectangleF(4.5, 4.5, 5, 3.0) 'dimensions in inches
Dim img3 As Image = PictureBox3.Image
Dim printArea3 As New RectangleF(8, 8, 5, 3.0) 'dimensions in inches
Dim f As New Font("Times New Roman", 14, FontStyle.Underline)
Dim g As New Font("Times New Roman", 14, FontStyle.Regular)
Dim b As New SolidBrush(Color.Black)
Dim c As Integer = 60
Dim xRes As Single = 90 'img1.HorizontalResolution / 2
Dim yRes As Single = 90 'img1.VerticalResolution / 2
e.Graphics.DrawImage(img1, printArea1.X * xRes, printArea1.Y * yRes, printArea1.Width * xRes, printArea1.Height * yRes)
e.Graphics.DrawImage(img2, printArea1.X * xRes, printArea2.Y * yRes, printArea2.Width * xRes, printArea2.Height * yRes)
e.Graphics.DrawImage(img3, printArea1.X * xRes, printArea3.Y * yRes, printArea3.Width * xRes, printArea3.Height * yRes)
e.Graphics.DrawString(Label1.Text, f, b, 600, 150)
e.Graphics.DrawString(Label2.Text, f, b, 600, 450)
e.Graphics.DrawString(Label3.Text, f, b, 600, 750)
e.Graphics.DrawString(RichTextBox1.Text, g, b, 600, 250)
e.Graphics.DrawString(RichTextBox2.Text, g, b, 600, 600)
e.Graphics.DrawString(RichTextBox3.Text, g, b, 600, 850)
End Sub
-
Nov 26th, 2012, 04:16 PM
#2
Re: Printing Contents of RTB
This is why I use the RichTextBoxPrintControl. Basically the problem is that RTB uses Chr(10) to mark line breaks instead of vbCrLf. You can correct this using string.Replace but remember that you first need to replace all Chr(10) with vbCrLf and then go back through again to erase any double Chr(13) that might create.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 26th, 2012, 06:10 PM
#3
Thread Starter
Frenzied Member
Re: Printing Contents of RTB
I have built that project and I get the same result when I test it. Is there something else that I need to do?
I am confused about your comment about string.replace, was this in lieu of using the RichTextBoxPrintCtrl or along with it
Thanks
-
Nov 26th, 2012, 06:27 PM
#4
Re: Printing Contents of RTB
The RTBPrintCtrl is designed to print the RTB content, the whole RTB content, and nothing but the RTB content. It wouldn't make any difference to what you're doing the way you're doing it. Having said that I've just checked the RTB output and actually it doesn't do what I thought it did so what you'll have to do is use the RTB.Lines() array to print each line separately. So ...
vb.net Code:
For Each ln In RichTextBox1.Lines
'drawstring(ln & vbCrLf)
Next
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|