确定所选文本是否是 RichTextBox 中的超链接?

发布于 2024-12-29 01:33:28 字数 307 浏览 5 评论 0原文

我还希望用所选超链接的 URL 填充文本框。我认为我沿着这段代码的正确道路,但我不知道如何完成它:

        TextPointer position = RichTextBoxEditor.Selection.Start;

        Inline parent = position.Parent as Inline;

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

        }

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>())
        {

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2025-01-05 01:33:28

是的...您走在正确的道路上。以前从未做过,但如果您的光标位于超链接内,则会为您提供超链接:

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

Hyperlink hl = position2.Parent as Hyperlink;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文