Selecting contiguous characters having a common style

2 posts, 0 answers
  1. George
    George avatar
    1 posts
    Member since:
    Apr 2009

    Posted 18 Apr 2011 Link to this post

    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 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

  2. Andrew
    Andrew avatar
    140 posts

    Posted 20 Apr 2011 Link to this post

    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.

    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
Back to Top