|
-
Sep 2nd, 2011, 08:43 AM
#1
Thread Starter
Addicted Member
Rich TextBox printing
Hi all
Got the following to print a richtext box (tbUpperBody)
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)
Dim rect As New Rectangle(75, 150, 680, 1000)
ev.Graphics.DrawString(tbUpperBody.Text, New Font("Courier New", _
14, FontStyle.Regular), Brushes.Black, rect)
ev.Graphics.DrawString(tbScriptName.Text, New Font("Courier New", _
14, FontStyle.Bold), Brushes.Black, 120, 120)
ev.HasMorePages = False
End Sub
'PRINT TOP SCRIPT PART 2
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 when the text that needs printed is more than one page long? it seems i can only get it to print infinite pages or one page, rather than the necessary number of pages...
help appreciated!
-
Sep 2nd, 2011, 08:00 PM
#2
Re: Rich TextBox printing
You are setting HasMorePages to False, so you're telling the PrintDocument that that are no more pages to print, so of course it prints no more pages. You are supposed to test whether there are more pages to print and then set HasMorePages accordingly.
I would suggest that you do some reading on the basics of .NET and printing and, most importantly, how the PrintPage event, as the name suggests, is used to print one page at a time. Go to the VB.NET CodeBank forum and sort by Thread Starter. Look down the list until you find threads by Merrion, who is the resident printing expert. There you'll find a beginners guide that will explain how to use HasMorePages.
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
|