c# - 链接标签打不开

标签 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");
    }
}

他们在不同的类(class)。 Form2 在 Form3 之前打开。 有什么问题吗?

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

最佳答案

你试图打开一个链接而不告诉程序如何或用什么打开该链接。你应该告诉它在程序或其他东西中搜索它!

关于c# - 链接标签打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13906471/

相关文章:

c# - 在执行方法的括号内声明变量

c# - Cross Thread错误处理形式与Timer

regex - 用正则表达式检查变音符号

c# - foreach + break vs linq FirstOrDefault 性能差异

javascript - 在 JavaScript 中创建时间戳

c# - Entity Framework 5 代码首先添加图像

c# - 将 int[] 连接到相同大小的 string[]

c# - Windows DataGridView _RowCommand

c# - MVVM 中的双向数据绑定(bind)问题

c# - AxImp .NET4.0 运行时不匹配