LinkLabel无法打开

时间:2012-12-16 23:21:08

标签: c# winforms .net-4.0 linklabel

我在Form2和Form3中使用相同的代码创建LinkLabel。 Form2和Form3是单独的类,因此名称不会干扰。它们都是创建的,但是在Form 3链接中打开,在Form2中没有任何反应。

这是Form2的代码

public partial class Form2 : Form
{
  public void createFormEntry(List<string> videoId)
  {
    LinkLabel link = new LinkLabel();
    link.Name = "link";
    link.AutoSize = true;
    link.Location = new Point(76, 8);
    link.Text = "www.example.com";
    link.LinkClicked += new LinkLabelLinkClickedEventHandler(link_LinkClicked);
    this.Controls.Add(link);
  }   

    private void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        System.Diagnostics.Process.Start("http://www.example.com");
    }
}

这适用于Form3

public partial class Form3 : Form
{
  private void createFormEntry(Feed<Video> videoFeed)
  {
    LinkLabel link = new LinkLabel();
    link.Name = "link";
    link.AutoSize = true;
    link.Location = new Point(76, 8);
    link.Text = "www.example.com";
    link.LinkClicked += new LinkLabelLinkClickedEventHandler(link_LinkClicked);
    this.Controls.Add(link);
  }

    private void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        System.Diagnostics.Process.Start("http://www.example.com");
    }
}

他们在不同的班级。 Form2在Form3之前打开。 可能有什么不对?

编辑:现在当我添加更多代码时,我在Form2中看到createFormEntry是public,而在Form3中它被设置为private。 这可能是个原因吗?

1 个答案:

答案 0 :(得分:0)

您试图打开链接而不告诉程序打开该链接的方式或内容。您应该告诉它在程序或其他内容中搜索它!