RTF String Position

lothos12345

Junior Contributor
Joined
May 2, 2002
Messages
294
Location
Texas
Using Visual Basic.NET I am trying to locate the inputposition of a particuliar string in a RichTextBox. This string can be located anywhere. The document I am searching is in an rtf format. The problem is that I can get the input position of the string in the rtf however when I try to replace it the string the input position is no longer correct. Because the replace looks at the document in a plain text format not an rtf format thus the input position is incorrect. I need to keep the format of the original rtf. Not sure what to do. Any help offered is greatly appreciated.
 
when you are searching the richtextbox, are you looking at the Richtextbox.Text or .RTF ?

if you search through it specifying .TEXT you will lose formatting, if you search through the actuall RTF ( richtextbox.RTF ) you shouldn't lose formatting.
 
RTF string addition

I am searching the rtf, the problem comes when I try to replace a word. It seems it will only take the position of the word as text not rtf. So when I try to get the input position of the word, it gives it to me relative to the rtf however when I try to replace the word, it takes the input postion and thinks it is a text position not rtf and puts the replacement in the wrong spot.
 
If you are replacing the text in the string, and you search the rtf, you should make the replacement in the rtf. If you search the plain text, you should make the replacement in the plain text. If you are trying to position the cursor within the text box (which is done by the plain text position) you must search the plain text. As long as you do one of the above, you shouldn't run into a misalignment issue.

You can not search the rtf and use that to position the cursor or selection unless you want to parse the rtf yourself and calculate the correct offset.

From what I see, you must either search the plain text instead of rtf, or make the replacement in the rtf instead of plain text. If you are worried about positioning the cursor correctly after modifying the rtf, you can search both the rtf and the plain text to find both offsets, make the rtf replacement and position the cursor using the plain text offset you found.

Hope I understood your question right or at least said something somewhat useful.
 
Back
Top