【发布时间】:2012-12-04 02:16:50
【问题描述】:
我正在使用相同的代码在 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 中它被设置为私有。 这可能是一个原因吗?
【问题讨论】:
-
当link_LinkClicked在Form3中声明为private void时,如何在Form2中访问呢?你还有其他代码吗?
-
嗨,我编辑了代码,希望现在更清楚了
-
启动你的调试器,看看问题出在哪里。我在您的代码 sn-p 中找不到任何内容。也许重要的位置在其他地方。也许您正在使用 foreach(videoFeed 中的 AtomEntry) 并且没有 AtomEntries。
标签: c# winforms .net-4.0 linklabel