Printing RichTextBox Contents


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Printing RichTextBox Contents

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    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.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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
    Quote Originally Posted by Psy View Post
    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

  3. #3
    Join Date
    Mar 2009
    Posts
    5
    Quote Originally Posted by Hack View Post
    Quote 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.

    Quote Originally Posted by Hack View Post
    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?

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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

  1. printing the contents of a rich text box
    By Prisim in forum VB Classic
    Replies: 5
    Last Post: 09-12-2008, 01:30 PM
  2. Printing document from richtextbox
    By Arvind in forum .NET
    Replies: 1
    Last Post: 03-20-2004, 07:19 AM
  3. Printing HTML Table contents.
    By Bambu in forum Web
    Replies: 1
    Last Post: 05-24-2001, 11:13 PM
  4. Printing contents of another window
    By Francesco Lari in forum Web
    Replies: 0
    Last Post: 01-28-2001, 02: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center