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

How to get current Hyperlink, when Caret is located in a Hyperlink

3 Answers 155 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
kun
Top achievements
Rank 1
kun asked on 25 Jan 2016, 03:06 PM

hello

Dear Telerik Team

We want to make: When caret enter into a Hyperlink, or delete a hyperlink, or press Backspace key to delete the Hyperlink, a popup is triggered. We used the method you provided to show a popup (use click), and was very successful.

1.But now question is that we can not distinguish whether it is a Hyperlink, when caret enter into the hyperlink.

2.Another question is that: how to programmly change the style of a Hyperlink.

 

Thanks, We hope your help.

 

Kun

3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 28 Jan 2016, 02:32 PM
Hi Kun,

You could detect if the caret is inside a hyperlink using the GetNextInline() method of the CaretPosition. From the Inline, you could extract if it is a Hyperlink using the following approach:
Inline inline = this.radRichTextBox.Document.CaretPosition.GetCurrentInline();
 
IHyperlinkRangeMarker hyperlink = inline.FieldStart as IHyperlinkRangeMarker;
if (hyperlink != null)
{
    // The caret position is inside a hyperlink
}

In order to change the behavior of the Backspace key, you could attach to the PreviewEditorKeyDown event of RadRichTextBox and execute the custom logic in the handler. There is an example of how to achieve this at the end of the Keyboard Support article.

You can obtain and modify the default hyperlink style of the document through the StyleRepository property of RadDocument.
StyleDefinition hyperlinkStyle = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.HyperlinkStyleName];

More information about the styles in RadRichTextBox is available in our documentation on that matter.

Hope this helps.

Regards,
Tanya
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
kun
Top achievements
Rank 1
answered on 29 Jan 2016, 03:28 AM

Hi, Tanya

We used codes you provided "StyleDefinition hyperlinkStyle =this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.HyperlinkStyleName]; ",and refered to  RadDocument

But we did not figure out how to define a custom style of Hyperlink.

We used the codes as follow, but it did not take effect:

StyleDefinition hyperlinkStyle =this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.HyperlinkStyleName];

StyleDefinition linkedParagraphStyle = new StyleDefinition();
                linkedParagraphStyle.Type = StyleType.Paragraph;
                linkedParagraphStyle.ParagraphProperties.Background = Colors.Yellow;
                linkedParagraphStyle.DisplayName = "linkedParagraphStyle";
                linkedParagraphStyle.Name = "linkedParagraphStyle";

                StyleDefinition linkedCharStyle = new StyleDefinition();
                linkedCharStyle.Type = StyleType.Character;
                linkedCharStyle.SpanProperties.FontWeight = FontWeights.Bold;
                linkedCharStyle.SpanProperties.FontSize = Unit.PointToDip(30);
                linkedCharStyle.SpanProperties.ForeColor = Colors.Purple;
                linkedCharStyle.DisplayName = "linkedCharStyle";
                linkedCharStyle.Name = "linkedCharStyle";
                linkedParagraphStyle.LinkedStyle = linkedCharStyle;

                progressNotes.radRichTextBox.Document.StyleRepository.Add(linkedParagraphStyle);
                progressNotes.radRichTextBox.Document.StyleRepository.Add(linkedCharStyle);

 

We hope your help, thank you very much

0
Tanya
Telerik team
answered on 01 Feb 2016, 04:30 PM
Hi Kun,

You will need to create a new StyleDefinition object only if the goal is to create a new style. If I understand your requirement correctly, you need to modify the built-in style for hyperlinks. If so, you could obtain it through the StyleRepository of RadDocument and directly change its properties according to your preferences.

Hope this makes things clear.

Regards,
Tanya
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
kun
Top achievements
Rank 1
Answers by
Tanya
Telerik team
kun
Top achievements
Rank 1
Share this question
or