Add and remove RTF-text in a RichTextBox at runtime?

M

M O J O

Hi,

How do I add and remove PART of the RTF-text in a RichTextBox?

If I use...

MyRichTextBox.Text = "New text" & MyRichTextBox.Text

.... then all my RTF (higlight, bold, underline and so on) is removed.


Thanks!

M O J O
 
H

Herfried K. Wagner [MVP]

* M O J O said:
How do I add and remove PART of the RTF-text in a RichTextBox?

If I use...

MyRichTextBox.Text = "New text" & MyRichTextBox.Text

... then all my RTF (higlight, bold, underline and so on) is removed.

Select the text by calling the overloaded version of the control's
'Select' method and the set its 'SelectedText' property to "".
 
P

Peter Huang

Hi Mojo,

Thanks for posting in the community. My name is Peter, and I will be
assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to add or remove part of
the RTF-Text in a RichTextBox.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I agree with Herfried's suggestion.
For RTF-Text you may try the SelectedRtf as below.

Dim o As New RichTextBox
o.Rtf = "{\rtf1\ansi This is in \b bold\b0.}"
Me.Controls.Add(o)
'The line will insert the rtf where the curser is.
o.SelectedRtf = "{\rtf1\ansi This is in \b bold\b0.}"
'This will remove part of the RTF-Text.
o.Select(5,7)
o.SelectedRtf = ""

For detailed information, you may take a look at the demo below.
Insert Plain Text and Images into RichTextBox at Runtime
http://www.codeproject.com/cs/miscctrl/CsExRichTextBox.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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