文本区域和超链接

文本区域和超链接

本文介绍了文本区域和超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个快速,容易对C#在Visual Studio中的问题。首先,有没有像标签东西,但在程序文本的区域?我想有多行文字在我的计划,但只能似乎与DotNetBar标签来完成它换行开启。

I have two quick, easy questions on C# in Visual Studio. First, is there anything like the label, but for an area of text in the program? I would like to have multiple lines of text in my program, but can only seem to accomplish it with a DotNetBar label with wordwrap turned on.

二,有没有什么办法让文本中间的超链接不使用链接标签?如果我想生成文本,如有可用更新,请访问来下载吧! ,是有可能使链接点击,而无需在文本的中间位置的链接标签?

Second, is there any way to have a hyperlink in the middle of the text without using a link label? If I wanted to generate text like "An update is available, please visit http://example.com to download it!", is it possible to make the link clickable without having to position a link label in the middle of the text?

推荐答案

可以使用并设置它的属性:

You can use a LinkLabel and set its LinkArea property:

 //LinkArea (start index, length)
 myLinkLabel.LinkArea = new LinkArea(37, 18);
 myLinkLabel.Text = "An update is available, please visit http://example.com to download it!";



以上会使 http://example.com ,而文字的正常休息的链接

The above will make the http://example.com a link whilst the rest of the text in normal.

编辑回答评论:
有处理链接的各种方式。一种方法是给链接描述(URL),然后启动使用的Process.Start的URL。

Edit to answer comment:There are various ways of handling the link. One way is to give the link a description (the URL) and then launch the URL using Process.Start.

myLinkLabel.LinkArea = new System.Windows.Forms.LinkArea(37, 18);
myLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(myLinkLabel_LinkClicked);
myLinkLabel.Text = "An update is available, please visit http://example.com to download it!";
myLinkLabel.Links[0].Description = "http://example.com";

和事件处理程序可以阅读说明书并启动网站:

And the event handler can read the description and launch the site:

void myLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    Process.Start(e.Link.Description);
}

这篇关于文本区域和超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 09:04