首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C#中使用代理打开链接

在C#中使用代理打开链接
EN

Stack Overflow用户
提问于 2016-05-12 20:08:09
回答 2查看 86关注 0票数 0

我试图让我的链接打开在一个网页浏览器。

对于for循环中的委托,一切都很好,但是在eventGen()方法中,我尝试获取单击的链接的名称,其中一个链接将字符串nameOfLink作为.

"System.Windows.Forms.LinkLabel,文本:程序员的Quora“

在使用if语句验证所选名称并打开链接时,即使我将文本更改为

代码语言:javascript
复制
nameOfLink.Equals("Quora For Programmers");


namespace VisitedSites
{
    public partial class frmRecentlyVisitedSites : Form
    {
        // Create an array of Link labels
        LinkLabel[] sites = new LinkLabel[3];

        // Create links with the tool tips
        LinkLabel lnkQuora = new LinkLabel();
        ToolTip quora = new ToolTip();

        // Create links with the tool tips
        LinkLabel lnkIndeed = new LinkLabel();
        ToolTip indeed = new ToolTip();

        // Create links with the tool tips
        LinkLabel lnkHackerRank = new LinkLabel();
        ToolTip hackerRank = new ToolTip();

        public frmRecentlyVisitedSites()
        {
            InitializeComponent();

        }

        private void frmRecentlyVisitedSites_Load(object sender, EventArgs e)
        {
            // Populate the array with links 
            sites[0] = lnkQuora;
            quora.SetToolTip(lnkQuora, "Quora For Questions!");
            sites[1] = lnkIndeed;
            indeed.SetToolTip(lnkIndeed, "Qualified For Jobs!");
            sites[2] = lnkHackerRank;
            hackerRank.SetToolTip(lnkHackerRank, "Comfortable Coding?");

            // Configure the LinkLabel's properties. 
            this.lnkQuora.Location = new System.Drawing.Point(37, 36);
            this.lnkQuora.AutoSize = true;
            this.lnkQuora.Text = "Quora For Programmers";

            // Configure the LinkLabel's properties. 
            this.lnkIndeed.Location = new System.Drawing.Point(37, 56);
            this.lnkIndeed.AutoSize = true;
            this.lnkIndeed.Text = "Indeed For The Skilled";

            // Configure the LinkLabel's properties. 
            this.lnkHackerRank.Location = new System.Drawing.Point(37, 76);
            this.lnkHackerRank.AutoSize = true;
            this.lnkHackerRank.Text = "Hacker Rank For The Robust";

            for (int i = 0; i < sites.Length; i++)
            {
                this.Controls.Add(sites[i]);
                sites[i].LinkClicked += new LinkLabelLinkClickedEventHandler(EventGen);
            }

        }
        private void EventGen(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Determine the name of the link
            string nameOfLink = sender.ToString();

            // process the link depending on the name
            if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Quora For Programmers", StringComparison.InvariantCultureIgnoreCase))
            {
                lnkQuora.LinkVisited = true;
                System.Diagnostics.Process.Start("https://www.quora.com/");
            }
            else if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Indeed For The Skilled", StringComparison.InvariantCultureIgnoreCase))
            {
                lnkQuora.LinkVisited = true;
                System.Diagnostics.Process.Start("https://www.indeed.com/");
            }
            else if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Hacker Rank For The Robust", StringComparison.InvariantCultureIgnoreCase))
            {
                lnkQuora.LinkVisited = true;
                System.Diagnostics.Process.Start("https://www.hackerrank.com/");
            }


        }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-12 20:24:35

刚刚尝试了您的代码,您缺少的一个空格是

代码语言:javascript
复制
System.Windows.Forms.LinkLabel, Text: Quora For Programmers

而不是

代码语言:javascript
复制
System.Windows.Forms.LinkLabel, Text:Quora For Programmers
票数 0
EN

Stack Overflow用户

发布于 2016-05-12 20:19:34

为什么不将链接,例如"https://www.quora.com/“添加到link.LinkData = "https://www.quora.com/”之类的链接数据中,然后使用Process.Start(e.Link.LinkData作为字符串)打开该链接?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37196489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档