• Advertisement
Sign in to follow this  

[.net] Copying Text between two RichTextBox Controls.

This topic is 4470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an application in which I have two Rich Text Boxes. The text in box one is formated by the user(Color, Font, Etc). I then need to copy this text and cancatenate it to the formated text already in box two. Think of AOL Instant Messenger's IM Dialogs as an example. Its looking like there is no easy way to accomplish this task. I was hoping that there was some library functions to do this. However I fear that I may need to parse the RTF string myself. Can any one point me in the right direction towards completing this task? Thanks. Bill

Share this post


Link to post
Share on other sites
Advertisement
This almost does the trick. The only problem is the insertion position...

richTextBox2.Rtf = richTextBox2.Rtf.Insert(richTextBox2.SelectionStart, richTextBox1.SelectedRtf);

Cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by ernow
This almost does the trick. The only problem is the insertion position...

richTextBox2.Rtf = richTextBox2.Rtf.Insert(richTextBox2.SelectionStart, richTextBox1.SelectedRtf);

Cheers



' Select all the text in richTextBox1.
richTextBox1.SelectionStart = 0
richTextBox1.SelectionLength = richTextBox1.Text.Length

' Insert the text from richTextBox1 richTextBox2.
richTextBox2.Select(m_richTextBox2.Text.Length, 0)
richTextBox2.SelectedRtf = m_richTextBox1.SelectedRtf

' Add A new Line Feed Character at the end of the line.
richTextBox2.Select(richTextBox2.Text.Length, 0)
richTextBox2.SelectedText = vbCrLf



Had trouble making your method work, but ended up discovering this method. Not very straight forward at first glance, but it works how I need it perfectly.

Bill

Share this post


Link to post
Share on other sites
My solution only works when you select a part of the content of the first rtb and set the cursor in the second. My line of code will then insert the selected part of the first inside the second. (Should have writen that in my previous post...)

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement