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 :

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        Dim Print_Dialog As New PrintDialog
        Print_Dialog.Document = PreparePrintDocument()
        Print_Dialog.ShowDialog()
        If Print_Dialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Print_Dialog.Document.Print()
        End If
    End Sub

    Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
        Dim Print_Preview As New PrintPreviewDialog
        Print_Preview.Document = PreparePrintDocument()
        Print_Preview.WindowState = FormWindowState.Maximized
        Print_Preview.ShowDialog()
    End Sub

    Private Function PreparePrintDocument() As PrintDocument
        Dim Print_Document As New PrintDocument
        AddHandler Print_Document.PrintPage, AddressOf Print_PrintPage
        Return Print_Document
    End Function

    Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim Page As String
        Page = Me.Rtbbill.Text
        e.Graphics.DrawString(Page, Rtbbill.Font, Brushes.Black, 50, 50)
        e.HasMorePages = False
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.