C# 如何在编码模式下在标签中放置超链接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15044170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:52:33  来源:igfitidea点击:

How to put a hyperlink in a label, during coding mode?

c#texthyperlinkvisual-studio-2012label

提问by user2085275

I am creating a BMI calculator, and I am wondering how to let a user click on a hyperlink when a text coded to show in a label. This is what I have so far.:

我正在创建一个 BMI 计算器,我想知道当文本编码显示在标签中时如何让用户单击超链接。这是我到目前为止。:

else if (bmi >= 35 && bmi <= 40)
{
     bodytypetextLabel.Text = "Visit this website. http://www.sears.com/fitness-sports-treadmills/c-1020252";
}

I'm not sure what to put in front of the "" Hyperlink so that it is made available as a hyperlink in run form for a user to click if he runs into that BMI result. Please help. Thank you in advanced.

我不确定在 "" 超链接前面放什么,以便它可以作为运行形式的超链接使用,供用户在遇到 BMI 结果时单击。请帮忙。先谢谢了。

回答by Faaiz Khan

use a link label instead of regular label to enable the hyperlink functionality.

使用链接标签而不是常规标签来启用超链接功能。

You can visit herefor more information.

您可以访问这里了解更多信息。

回答by shashwat

Try this code:

试试这个代码:

bodytypetextLabel.Text = "Visit this website <a href=\"http://www.sears.com/fitness-sports-treadmills/c-1020252\">here</a>";

回答by n00b

You can just use an "a" tag, an "a" tag without a URL is just like a label. Hope this helps someone.

您可以只使用“a”标签,没有 URL 的“a”标签就像标签一样。希望这可以帮助某人。

回答by Nourein

it's very easy :

这很容易:

1. you need to add :

1.你需要添加:

    using System.Diagnostics;

2. it's that :

2.就是这样:

    private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        Process.Start("https://www.google.com");
    }