0

I have an RTF text box control, and there are certain parts of the textbox that I want to update. My plan was to enclose the update-able text within some hidden text markers. For example,

{\rtf1 \v startlab\v0 Diagnostic Results\v endlab\v0}

or even

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\lang1033\f0\fs17 {\rtf1\ansi{\v startlab}}Diagnostic Results{\rtf1\ansi{\v endlab}}\par}

That way, I can just do a search for the beginning and ending tags and replace the text in between.

The problem is that VB.NET re-organizes the RTF and it becomes very hard to search for them.

For example, the above rtf gets rendered into

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\lang1033\v\f0\fs17 startlab\v0 Diagnostic Results\v endlab\v0\par } It also seems that the textbox doesn't understand \v because the text is rendered as

startlabDiagnostic Resultsendlab

So......

My questions are as follows:

  1. Is there any way to have hidden text in a .NET rtf textbox?
  2. Failing that, is there any good way to replace a particular section of text without making the beginning and ending markers visible to the user?
mankowitz
  • 1,864
  • 1
  • 14
  • 32
  • RTB does not support hidden text. A hokey alternative is to use SelectionColor and give the text a different color that's only off by 1 or 2 in blue so the difference isn't visible to the human eye. Finding it back is not cheap however. Separate the data from the view to get ahead. – Hans Passant Nov 08 '15 at 22:17
  • The ultimate goal is to have the rest of the box editable, and this one part of it gets updated as needed. Separating into separate text boxes makes the UI cluttered. – mankowitz Nov 08 '15 at 22:26
  • That's not what that means. You'll have to use the SelectionProtected property if you want to support editing so the user can't screw up the "marks". – Hans Passant Nov 08 '15 at 22:30
  • That might be the key. Is there a way to programmatically detect and change text that is "protected". How is that represented in rtf? Incidentally, I found that I could use `/ri3` which sets a right indent of 3/1440 inches which is undetectable. – mankowitz Nov 09 '15 at 14:31

0 Answers0