如何在 RichTextBox 中创建超链接?

编程入门 行业动态 更新时间:2024-10-09 20:25:57
本文介绍了如何在 RichTextBox 中创建超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我将 www.stackoverflow 添加到我的 RichTextBox 并运行该程序时,它以蓝色显示并作为超链接显示,但是当我单击它时什么也没有发生.我该如何解决这个问题?

When I add www.stackoverflow into my RichTextBox and run the program it is shown in blue and as a hyperlink yet when I click it nothing happens. How can I fix this?

推荐答案

  • 确保文本属性包含有效的 url.例如.www.stackoverflow/

    将 DetectUrls 属性设置为 true

    为 LinkClicked 事件编写一个事件处理程序.

    Write an event handler for the LinkClicked event.

    就我个人而言,我不会像 Microsoft 建议的那样将 "IExplore.exe" 作为参数传递给 Process.Start 调用,因为这假定它已安装,并且是用户的首选浏览器.如果您只是将 url 传递给进程启动(如下所示),那么 Windows 将做正确的事情并使用适当的 url 启动用户的首选浏览器.

    Personally, I wouldn't pass "IExplore.exe" in as a parameter to the Process.Start call as Microsoft advise as this presupposes that it is installed, and is the user's preferred browser. If you just pass the url to process start (as per below) then Windows will do the right thing and fire up the user's preferred browser with the appropriate url.

    private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) { System.Diagnostics.Process.Start(e.LinkText); }
  • 更多推荐

    如何在 RichTextBox 中创建超链接?

    本文发布于:2023-11-28 08:42:01,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1641706.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:超链接   如何在   RichTextBox

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!