Determine if selected text is Hyperlink in RichTextBox?

孤者浪人 提交于 2019-12-10 12:14:57

问题


I also am hoping to populate a text box with the URL of the selected Hyperlink. I think I am along the right path with this code, but I don't know how to complete it:

        TextPointer position = RichTextBoxEditor.Selection.Start;

        Inline parent = position.Parent as Inline;

        foreach (Hyperlink hl in RichTextBoxEditor.Blocks.OfType<Hyperlink>())
        {

        }

回答1:


Yes... you are in the right path. Never done before but if your cursor is inside an hyperlink this gives you the hyperlink:

TextPointer position1 = richTextBox1.Selection.Start;
Inline parent = position1.Parent as Inline;
TextPointer position2 = parent.ElementStart;

Hyperlink hl = position2.Parent as Hyperlink;


来源:https://stackoverflow.com/questions/8994783/determine-if-selected-text-is-hyperlink-in-richtextbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!