如何在RichTextBox中创建超链接?

时间:2022-08-25 17:18:20

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

当我将www.*.com添加到我的RichTextBox并运行程序时,它显示为蓝色和超链接,但当我点击它时没有任何反应。我怎样才能解决这个问题?

4 个解决方案

#1


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

    确保text属性包含有效的url。例如。 http://www.*.com/

  2. set the DetectUrls property to true

    将DetectUrls属性设置为true

  3. Write an event handler for the LinkClicked event.

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

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.

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

private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) {
    System.Diagnostics.Process.Start(e.LinkText);
}

#2


RichTextBox class allows you to customize its behavior when user clicks the hyperlink. Add an event handler for the RichTextBox.LinkClicked event

RichTextBox类允许您在用户单击超链接时自定义其行为。为RichTextBox.LinkClicked事件添加事件处理程序

Process p = new Process();

private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
   p = Process.Start("IExplore.exe", e.LinkText);
}

#3


You should make sure that DetectUrls is set to true. If that doesn't work on its own, you may need to add a handler for the LinkClicked event.

您应确保将DetectUrls设置为true。如果这不起作用,您可能需要为LinkClicked事件添加处理程序。

#4


Is yourTextBox.DetectUrls set to true? We may need some more info to provide a better answer.

yourTextBox.DetectUrls是否设置为true?我们可能需要更多信息来提供更好的答案。

#1


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

    确保text属性包含有效的url。例如。 http://www.*.com/

  2. set the DetectUrls property to true

    将DetectUrls属性设置为true

  3. Write an event handler for the LinkClicked event.

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

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.

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

private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) {
    System.Diagnostics.Process.Start(e.LinkText);
}

#2


RichTextBox class allows you to customize its behavior when user clicks the hyperlink. Add an event handler for the RichTextBox.LinkClicked event

RichTextBox类允许您在用户单击超链接时自定义其行为。为RichTextBox.LinkClicked事件添加事件处理程序

Process p = new Process();

private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
   p = Process.Start("IExplore.exe", e.LinkText);
}

#3


You should make sure that DetectUrls is set to true. If that doesn't work on its own, you may need to add a handler for the LinkClicked event.

您应确保将DetectUrls设置为true。如果这不起作用,您可能需要为LinkClicked事件添加处理程序。

#4


Is yourTextBox.DetectUrls set to true? We may need some more info to provide a better answer.

yourTextBox.DetectUrls是否设置为true?我们可能需要更多信息来提供更好的答案。