如何在RichTextBox中使超链接工作? [英] How can I make a hyperlink work in a RichTextBox?

查看:40
本文介绍了如何在RichTextBox中使超链接工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I add www.stackoverflow.com 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?

推荐答案


  1. 请确保text属性包含有效的网址。例如。 http://www.stackoverflow.com/

set DetectUrls 属性设置为 true

set the DetectUrls property to true

LinkClicked 编写事件处理程序>事件。

Write an event handler for the LinkClicked event.

个人而言,我不会在 IExplore.exe 中传递作为Microsoft建议的 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中使超链接工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆