How can one get hidden text without parsing Rtf in RichTextBox?

  • Thread starter Thread starter RobertGustafson
  • Start date Start date
R

RobertGustafson

Guest
WHAT I HAVE:

Visual Basic 2019, WinForms

MY PROBLEM:

When a program has a target platform of .NET 4.6.1 or lower, the Text property returns all text in a RichTextBox, including any hidden text (text inserted using "\v" Rtf tag). When targeted for .NET 4.7.1, it only returns the visible text. For example, if I do the following:

rtb.Rtf = "{\rtf1visible text \v hidden text \v0visible text}"

then rtb.Text returns "visible text hidden text visible text" in all platforms, except .NET 4.7.1, where it returns only "visible text visible text".

Some of my programs depend on the hidden text being accessible as plain text. I'd like to be able to read the invisible text at its caret position without having to parse the Rtf text--which is problematic because there's no correlation between the position of the text within the Rtf string and its caret position within the control, and I would then have to manually (!) convert the Rtf text for the hidden text to plain text. The change in RichTextBox behavior also complicates efforts to accurately or safely parse substrings within the Rtf.Text string (i.e., Rtf.Text.Substring(pos, length)), as string positions don't necessarily line up with caret positions when there's hidden text!

Other than targeting all such programs for .NET 4.6.1 or lower, do I have any options?! (BTW, I'd like to use as few Win32 APIs a possible.)

Please respond ASAP, and give any solutions in VB.








Robert Gustafson

Continue reading...
 
Back
Top