printing Richtextbox

S

Simon Whale

Hello,

not sure if this is best started here but here goes;

I have a richtextbox on a form, I can bold text, Italic and underline
without a problem. I can print the text from the Richtextbox control to
either the print or to file via a pdf progam, but I keep loosing the format
of the bold, underline and italic characters.

For printing i am using this example

http://msdn.microsoft.com/en-us/library/ms996492(printer).aspx

to get the bold on screen i am using

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripButton1.Click

Me.RichTextBox1.SelectionStart =
Me.RichTextBox1.Find(Me.RichTextBox1.SelectedText)

Dim bfont As New System.Drawing.Font(RichTextBox1.SelectionFont,
FontStyle.Bold)

RichTextBox1.SelectionFont = bfont

bfont = Nothing

End Sub



Any help that you can give me, would be of great help



Thanks

Simon
 
M

Morten Wennevik [C# MVP]

Hi Simon,

You will overwrite any style found in the selection with the new font, so
any italic parts will end up only bold afterwards. To keep italic and add
bold to it, you need to either add any previous styles found in the
selection, or change the style manually by editing the rtf codes yourself.
If there are more than one style in the selection you will only see the first
font in SelectionFont, so you need to use the second option if you want to
preserve all fonts. I wrote some code for the second solution a few weeks
back

[how to retain the richtext styles
http://social.msdn.microsoft.com/Fo...l/thread/00c94ae0-81ed-4d9f-8499-469f3ba6de59
 
S

Simon Whale

Morten,

thanks for that but i also kept the seach going and found an answer that i'd
like to share

http://support.microsoft.com/default.aspx?scid=kb;en-us;811401

this worked by creating a custom class that inherits the richtextbox control

Thanks
Simon
Morten Wennevik said:
Hi Simon,

You will overwrite any style found in the selection with the new font, so
any italic parts will end up only bold afterwards. To keep italic and add
bold to it, you need to either add any previous styles found in the
selection, or change the style manually by editing the rtf codes yourself.
If there are more than one style in the selection you will only see the
first
font in SelectionFont, so you need to use the second option if you want to
preserve all fonts. I wrote some code for the second solution a few weeks
back

[how to retain the richtext styles]
http://social.msdn.microsoft.com/Fo...l/thread/00c94ae0-81ed-4d9f-8499-469f3ba6de59



--
Happy Coding!
Morten Wennevik [C# MVP]


Simon Whale said:
Hello,

not sure if this is best started here but here goes;

I have a richtextbox on a form, I can bold text, Italic and underline
without a problem. I can print the text from the Richtextbox control to
either the print or to file via a pdf progam, but I keep loosing the
format
of the bold, underline and italic characters.

For printing i am using this example

http://msdn.microsoft.com/en-us/library/ms996492(printer).aspx

to get the bold on screen i am using

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles ToolStripButton1.Click

Me.RichTextBox1.SelectionStart =
Me.RichTextBox1.Find(Me.RichTextBox1.SelectedText)

Dim bfont As New System.Drawing.Font(RichTextBox1.SelectionFont,
FontStyle.Bold)

RichTextBox1.SelectionFont = bfont

bfont = Nothing

End Sub



Any help that you can give me, would be of great help



Thanks

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top