-
Aug 17th, 2011, 05:49 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Print Rich Text Box
Hello
Using the following code to print the contents of my rich textbox
Code:
Private Sub PrintText(ByVal sender As Object, _
ByVal ev As PrintPageEventArgs)
tbUpperBody.Text = vbNewLine &
vbNewLine &
tbUpperBody.Text
Dim blackPen As New Pen(Color.Black, 3)
' Create points that define line.
Dim point1 As New Point(75, 150)
Dim point2 As New Point(725, 150)
' Draw line to screen.
ev.Graphics.DrawLine(blackPen, point1, point2)
ev.Graphics.DrawString(tbUpperBody.Text, New Font("Arial", _
14, FontStyle.Regular), Brushes.Black, 120, 120)
ev.HasMorePages = False
End Sub
Private Sub PrintTopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintTopToolStripMenuItem.Click
Try
Dim PrintDoc As New PrintDocument
AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText
PrintDoc.Print()
tbUpperBody.Multiline = True
Catch ex As Exception
MessageBox.Show("Sorry - there was a problem with printing", ex.ToString())
End Try
End Sub
Issue is that when the rich textbox contains text that is spread over multiple lines, it prints as one massive line, which obviously disappears off the edge of the page.
how can i get it to print with line breaks?
thanks
-
Aug 17th, 2011, 08:10 AM
#2
Re: Print Rich Text Box
The Text property of a TextBox or RichTextBox just returns a string of characters -- no formatting, line endings etc. But you can print a string with word wrapping by using the version of Graphics.DrawString with a Rectangle argument, for example:
Code:
Dim rect As New Rectangle(120, 120, 250, 250)
ev.Graphics.DrawString(tbUpperBody.Text, New Font("Arial", _
14, FontStyle.Regular), Brushes.Black, rect)
It's up to you to decide the position and size of the rectangle.
BB
-
Aug 17th, 2011, 08:48 AM
#3
Thread Starter
Addicted Member
Tags for this Thread
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
|