日期:2014-05-18 浏览次数:20757 次
((LinkLabel)panel1.Controls[a]). ??? += new LinkLabelLinkClickedEventHandler(this.ButtonArray_OnClick);
------解决方案--------------------
3楼正解,你必须先进行类型转换
------解决方案--------------------
private LinkLabel[] LL = new LinkLabel[10];
private void Form1_Load(object sender, EventArgs e)
{
int a = 0;
int x = 0, y = 0;
for (a = 0; a <= 5; a++)
{
LinkLabel laber = new LinkLabel();
laber .Text = "这是第" + a.ToString() + "LinkLabel";
///
////
laber.Onclick+=new LinkLabelLinkClickedEventHandler(this.ButtonArray_OnClick);
panel1.Controls.add(laber);
}
}
private void ButtonArray_OnClick(object sender, LinkLabelLinkClickedEventArgs e)
{
LinkLabelLinkClickedEventArgs arg = (LinkLabelLinkClickedEventArgs)e;
LinkLabel l_1 = (LinkLabel)sender;
if (arg.Button == MouseButtons.Left)
{
MessageBox.Show(l_1.Name.ToString());
}
}
------解决方案--------------------
private LinkLabel[] LL = new LinkLabel[10]; private void Form1_Load(object sender, EventArgs e) { int a = 0; int x = 0, y = 0; for (a = 0; a <= 5; a++) { LL[a] = new LinkLabel(); LL[a].Text = "这是第" + a.ToString() + "LinkLabel"; LL[a].Width = panel1.Width / 3; LL[a].Left = x * LL[a].Width; LL[a].Height = panel1.Height / 10; LL[a].Top = y * LL[a].Height; LL[a].Name = "LL" + a.ToString(); LL[a].Onclick += new Link