locked
how to print a rich text box RRS feed

  • Question

  • HELP!

    How do you print rich text boxes?

    Tuesday, May 16, 2006 10:28 PM

Answers

  • Look at the PrintDocument class in Visual basic.  Here is a scaled down, generic example (this is assuming VS2005 and all controls referenced below are added, and does not account for paging or line counting):

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    With PrintDocument1

    .PrinterSettings = PrintDialog1.PrinterSettings.Clone

    .Print()

    End With

    End If

    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    RichTextBox1.SelectAll()

    e.Graphics.DrawString(RichTextBox1.SelectedText, RichTextBox1.SelectionFont, Brushes.Black, New System.Drawing.RectangleF(e.MarginBounds.Top, e.MarginBounds.Left, e.PageBounds.Width, e.PageBounds.Height))

    e.HasMorePages = False

    End Sub

    Wednesday, May 17, 2006 6:33 PM

All replies

  • Look at the PrintDocument class in Visual basic.  Here is a scaled down, generic example (this is assuming VS2005 and all controls referenced below are added, and does not account for paging or line counting):

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    With PrintDocument1

    .PrinterSettings = PrintDialog1.PrinterSettings.Clone

    .Print()

    End With

    End If

    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    RichTextBox1.SelectAll()

    e.Graphics.DrawString(RichTextBox1.SelectedText, RichTextBox1.SelectionFont, Brushes.Black, New System.Drawing.RectangleF(e.MarginBounds.Top, e.MarginBounds.Left, e.PageBounds.Width, e.PageBounds.Height))

    e.HasMorePages = False

    End Sub

    Wednesday, May 17, 2006 6:33 PM
  • Thanks MacMatt_98! 

    Friday, May 19, 2006 1:05 PM
  • Thank you, I have been looking for this for some time now..

     

     

    Friday, July 7, 2006 8:30 PM