How to make linklabel work
im trying to make a list of linklabels the link to all linklabels is the same exept
an idnumber from MyClass but i am out of ideas how to make it work.
does anyone know what i need to make it work ?
ArrayList list = new ArrayList();
private LinkLabel[] lutt = new LinkLabel[100];
int t=0;
foreach (MyClass s in list)
{
lutt[t] = new LinkLabel();
lutt[t].Location = new System.Drawing.Point(10, 80 + (tl * 25));
lutt[t].Name = "";
lutt[t].Text = "more";
this.Controls.Add(lutt[t]);
t=t+1;
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted Jul 17, 2007, 1:35 PM EDT
public partial class Form1 : Form { public Form1() { InitializeComponent(); CreateMyClassList(); CreateLinkLabels(); } private void CreateMyClassList() { list.Add(new MyClass(1)); list.Add(new MyClass(2)); list.Add(new MyClass(3)); list.Add(new MyClass(4)); } private LinkLabel[] lutt = new LinkLabel[100]; ArrayList list = new ArrayList(); public void CreateLinkLabels() { int t=0; foreach (MyClass s in list) { lutt[t] = new LinkLabel(); lutt[t].Location = new System.Drawing.Point(10, 80 + (t * 25)); lutt[t].Name = "link" + s.ID; lutt[t].Text = "more " + s.ID; lutt[t].Click += new EventHandler(Form1_Click); this.Controls.Add(lutt[t]); t=t+1; } } private void Form1_Click(object sender, EventArgs e) { switch (((LinkLabel)sender).Name) { case "link1": MessageBox.Show("pressed link 1"); break; case "link2": MessageBox.Show("pressed link 2"); break; default: break; } } }henrik3 pointsPosted Jul 17, 2007, 3:31 PM EDT