C#我怎样才能使一个RichTextBox中的超链接工作? [英] C# How can I make a hyperlink work in a RichTextBox?

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

问题描述

当我加入www.stackoverflow.com到我的RichTextBox并运行它以蓝色和超链接显示的程序但当我单击它什么也不会发生。我该如何解决这个问题?

感谢


解决方案

  1. 请确保文本属性包含有效的URL。例如。 http://www.stackoverflow.com/


  2. DetectUrls 属性的真正


  3. 对于写在 LinkClicked 事件的事件处理程序。


就个人而言,我不会通过的IEXPLORE.EXE作为到的Process.Start 拨打微软参数建议,因为这presupposes它是安装,并且是用户的preferred浏览器。如果你只是通过链接直接处理的开始(按以下),则Windows将做正确的事,并火起来的用户的preferred浏览器相应的URL。

 私人无效mRichTextBox_LinkClicked(对象发件人,LinkClickedEventArgs E){
    System.Diagnostics.Process.Start(e.LinkText);
}

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?

Thanks

解决方案

  1. Make sure the text property includes a valid url. E.g. http://www.stackoverflow.com/

  2. set the DetectUrls property to true

  3. Write an event handler for the LinkClicked event.

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);
}

这篇关于C#我怎样才能使一个RichTextBox中的超链接工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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