Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
  • Leaders
Posted

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.

Posted

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.

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...