RichTextBox Appending Text Inbetween Data

iDeveloper

New member
Joined
Oct 23, 2010
Messages
4
Programming Experience
1-3
I would like to know how it's possible to append text between data.

For example:

I have a RTB with "ABC" on the first line and "DEF" on the third line. My question is how would I insert text data into the second line, without changing any existing data.

Thanks.
 
If you are inserting data into the middle then it's not appending. By definition, appending is adding to the end.

To answer your question, set the SelectionStart property to the character index at which you want to position the caret. You also need the Selectionlength set to zero, but that should happen automatically when you change the SelectionStart. You might want to set it explicitly just to be sure. You then set the SelectedText property to replace the existing selection with new text. If no text is selected, the new text is just inserted at the caret position.

Note that a line break is two characters (CR, LF) so you should take that into account. The RTB provides methods to do things like get the character index at the start of a line.
 
Back
Top