I have below code to print richtextbox text. My textbox contains Regular and bold text but below code print either bold or reguler text. How can i print text as it is in the text box.

 Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        If PrintDialog1.ShowDialog() = DialogResult.OK Then

            Try
                Dim printdoc As New PrintDocument
                AddHandler printdoc.PrintPage, AddressOf Me.PrintText
                printdoc.Print()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

        End If
    End Sub

   Private Sub PrintText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)


        Dim rect As New Rectangle(50, 75, 750,1000)
        ev.Graphics.DrawString(TbxBody.Text, New Font("Courier New", 11, FontStyle.Regular), Brushes.Black, rect)
        ev.HasMorePages = False
    End Sub

Hi

The reason you are not printing any formatted text is that you are explicitly stating in the DrawString method the font and font style to be used.

There is a step by step article on Microsoft that will show you how to create an extended version of the Rich Text Box control that supports printing:

How to print the contents of a rich text box control

Sorry Minimalist, didn't see your post when I submitted.

Edited 1 Year Ago by djjeavons

This article has been dead for over six months. Start a new discussion instead.