943,678 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 9262
  • VB.NET RSS
Mar 19th, 2009
0

Print the contents of RichTextBox

Expand Post »
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 :
VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
babitha162 is offline Offline
3 posts
since Mar 2009
Mar 20th, 2009
0

Re: Print the contents of RichTextBox

Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Back Up
Next Thread in VB.NET Forum Timeline: Cut Paste functionality to grid view





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC