This is a migrated thread and some comments may be shown as answers.

Selecting contiguous characters having a common style

1 Answer 51 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 18 Apr 2011, 10:32 PM
I am trying to replicate some basic functionality of a Windows Forms application, which I will here call Legacy. In a couple of places, Legacy allows users to drag and drop files as attachments. The filenames appear within text supplied by the user, underlined and with the forecolor green. I have this working. Subsequently, when the user double-clicks on a filename, the file selected by double-clicking is opened for viewing (assuming a suitable viewer is available). I have gotten double-click detection working and (for now) I am considering the viewer to be unrelated to the RadRichText control's functionality. Here is the problem:

Suppose I have text like: "Here's a screenshot: Bad Error.bmp" - where "Bad Error.bmp" is in green, underlined. When the user double-clicks on, say, the ".", I want the entire filename to be selected and to launch the (as yet hypothetical) viewer. I can easily select the word at, or nearest to, the current caret position. How can I select all contiguous characters that are green and underlined?

Having selected any text that is green and underlined (part of a filename), I thought I would start by verifying programmatically that is green and underlined. Given that some text is selected, all of which has the same style values, it seems from the documentation that this should work, but it doesn't:

                StyleDefinition style = this.CurrentEditingStyle;
                Color? foreColor = (Color?)style.GetPropertyValue(Span.ForeColorProperty);
                Color? underlineColor = (Color?)style.GetPropertyValue(Span.UnderlineColorProperty);

foreColor and underlineColor are Black and Black, which are the values for the surrounding text, or the default values for the document - not the correct values for the selected text, or at the caret position, as http://www.telerik.com/help/silverlight/radrichtextbox-features-working-with-radrichtextxbox.html#Current_Span led me think would be the case. Please explain.

Checking the underline color is a rather indirect way to determine whether text is underlined, but it does seem to work.

My two questions are in bold text above.

Actually, there is a third question, which is: If what I am trying to do won't work, can you suggest a different approach that will arrive at the same result? For example, it would serve the same purpose if one could track the positions of all hyperlinks and attachment filenames as the text was edited

Thanks,
George

1 Answer, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 20 Apr 2011, 02:27 PM
Hi George,

If there is more than one value for a given property in the selection, CurrentEditingStyle won't represent exactly what you need. However, by accessing the caret and getting the current inline where the caret is, you can get the appropriate style. The same can be done by enumerating all inlines that are selected. Have you evaluated using hyperlinks for the files? We support custom hyperlink actions by using the HyperlinkClicked event on RadRichTextBox/RadDocument.
If you have other questions, contact us again.

Regards,
Andrew
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
George
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Share this question
or