RichTextBoxes don't properly account for invisible text

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

RobertGustafson

Guest
WHAT I HAVE:

Visual Basic 2019, WinForms

MY PROBLEM:

As I noted in an earlier post, Text and SelectedText don't return "hidden text" ("\v" flag) in .NET 4.7.2, unlike earlier platforms. I was provided with a solution that uses reflection (particularly the private "WindowText" property) to get plain full and selected text, including hidden text, in .NET 4.7.2.

But now I've noticed some other issues that make it hard to reliably handle RTF info for selected text when some of it is hidden--in any platform.

When it comes to hidden text inside a RichTextBox--even with .NET 4.6.1 or lower--the behavior can be a bit flaky. Even the SelectedRtf and SelectionLength properties aren't 100% reliable!!

NEW ISSUE AS FOLLOWS:

If a region of text that is partially visible and partially hidden is selected, then those properties incorporate and account for hidden text only when that text is followed by visible text either within or immediately following the selected region. If a selection ends with hidden text and there's more hidden text immediately after the selection, it's possible that the last sub-region of hidden text, or even the entire selection, will be ignored by SelectedRtf, when it's read. (A few exceptions to this occur may occur when the selection also begins with hidden text [.NET 4.6.1 or lower] or the selection ends at the end of the document [.NET 4.7.2].)

Since the value given by SelectionLength, when it's read, is also affected (It won't necessarily return the same value as set with in such a situation!), selecting a region ending with hidden text (especially when it begins with visible text) then setting SelectedRtf or SelectedText won't necessarily replace all the targeted text, and Cut and Copy are hence not completely reliable.

Is there a way to get the entire selected Rtf text--possibly analogous to "WindowText"--regardless of where in the selection text is visible or hidden? (There's obviously no reliable way to extract a substring from the Rtf property string [which does reliably return everything] corresponding to selected text.) Also, is there a way to ensure that the full desired selection remains fully selected in case the selected text is to be modified?

NOTE: I prefer reflection to Win32 APIs when possible, I want something that will work with both .NET 4.7.2 and earlier platforms, and of course, I want VB code.

Robert Gustafson





Robert Gustafson

Continue reading...
 
Back
Top