Print the contents of RichTextBox

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 3
Reputation: babitha162 is an unknown quantity at this point 
Solved Threads: 0
babitha162 babitha162 is offline Offline
Newbie Poster

Print the contents of RichTextBox

 
0
  #1
Mar 19th, 2009
I have a form with one richtext box. This rtb has different formats for each line i.e., some text is in bold letters, some center aligned. Currently I am using the PrintDialog Box to print the contents of the rtb and Print Preview DialogBox to preview the contents. The problem is when I preview the contents I see everything left aligned and in common font for all the text.

Could someone please tell me how to print the contents of the RichTextBox with different formats.

This is how my code looks :
  1.  
  2. Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
  3. Dim Print_Dialog As New PrintDialog
  4. Print_Dialog.Document = PreparePrintDocument()
  5. Print_Dialog.ShowDialog()
  6. If Print_Dialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  7. Print_Dialog.Document.Print()
  8. End If
  9. End Sub
  10.  
  11. Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
  12. Dim Print_Preview As New PrintPreviewDialog
  13. Print_Preview.Document = PreparePrintDocument()
  14. Print_Preview.WindowState = FormWindowState.Maximized
  15. Print_Preview.ShowDialog()
  16. End Sub
  17.  
  18. Private Function PreparePrintDocument() As PrintDocument
  19. Dim Print_Document As New PrintDocument
  20. AddHandler Print_Document.PrintPage, AddressOf Print_PrintPage
  21. Return Print_Document
  22. End Function
  23.  
  24. Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  25. Dim Page As String
  26. Page = Me.Rtbbill.Text
  27. e.Graphics.DrawString(Page, Rtbbill.Font, Brushes.Black, 50, 50)
  28. e.HasMorePages = False
  29. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Print the contents of RichTextBox

 
0
  #2
Mar 20th, 2009
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC