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

Recommended Answers

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 …

Jump to Post

All 4 Replies

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.

No worries, happend to me a few times lately.
Cheers

Thanks
the link http://support.microsoft.com/kb/811401/en-us was helpful.

i want to have default margin setting for left,right,height and width of page for printing on letter head instead of changing through page setup.

Be a part of the DaniWeb community

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