-
Printing RichTextBox Contents
Hi,
I need some help with some code to print the contents of a RichTextBox. I don't have any for it because I keep deleting it when I try something new.
Thanks.
-
Add a PrintDocument to your form and try this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)
e.Graphics.DrawString(RichTextBox1.Text, fnt, Brushes.Black, 0, 0)
e.HasMorePages = False
End Sub
 Originally Posted by Psy
I don't have any for it because I keep deleting it when I try something new.
Huh?
You did have the code you want, but don't anymore because you deleted it?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
 Originally Posted by Hack
 Originally Posted by Psy
I don't have any for it because I keep deleting it when I try something new.
 Huh?
You did have the code you want, but don't anymore because you deleted it?
I had code that didn't work, so I kept deleting it to try something else.
 Originally Posted by Hack
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)
e.Graphics.DrawString(RichTextBox1.Text, fnt, Brushes.Black, 0, 0)
e.HasMorePages = False
End Sub
This works, but how do you print keeping all of the colors that are in the RTB, and the margins that it has set?
-
That will print the richtextbox the way it displays on the screen (at least it does for me) minus any colors. We never use colors in anything because we do not have any color printers.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By Prisim in forum VB Classic
Replies: 5
Last Post: 09-12-2008, 12:30 PM
-
Replies: 1
Last Post: 03-20-2004, 06:19 AM
-
Replies: 1
Last Post: 05-24-2001, 10:13 PM
-
By Francesco Lari in forum Web
Replies: 0
Last Post: 01-28-2001, 01:00 PM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks