我使用相同的代码在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是公共的,而在Form3中它被设置为私有。这会是一个原因吗?
发布于 2012-12-17 07:44:04
您试图打开链接,但没有告知程序如何打开该链接或在其中打开该链接的内容。你应该告诉它在一个程序或者别的什么地方搜索它!
https://stackoverflow.com/questions/13906471
复制相似问题