[.net] Copying Text between two RichTextBox Controls.

Started by
2 comments, last by ernow 18 years, 4 months ago
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
Advertisement
This almost does the trick. The only problem is the insertion position...

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

Cheers
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
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

This topic is closed to new replies.

Advertisement