Label lb1 = new Label(); lb1.Name = "panel"+j; lb1.BackColor = Color.Transparent; lb1.BorderStyle = BorderStyle.FixedSingle; Panel1.Controls.Add(lb1);
為這些label增加Click事件
Label lb1 = new Label(); lb1.Name = "panel"+j; lb1.BackColor = Color.Transparent; lb1.Click += new EventHandler(label_Click); lb1.BorderStyle = BorderStyle.FixedSingle;Panel1.Controls.Add(lb1);string name = "";private void label_Click(object sender, EventArgs e){ Label lbl = sender as Label; name = lbl.Name;}
然後在Button2的Click中:
private void button2_Click(object sender, EventArgs e){ Label lbl = Panel1.Controls[name]; if(lbl != null) Panel1.Controls.Remove(lbl);}
Label lb1 = new Label(); lb1.Name = "panel"+j; lb1.BackColor = Color.Transparent; lb1.BorderStyle = BorderStyle.FixedSingle; Panel1.Controls.Add(lb1);
為這些label增加Click事件
Label lb1 = new Label(); lb1.Name = "panel"+j; lb1.BackColor = Color.Transparent; lb1.Click += new EventHandler(label_Click); lb1.BorderStyle = BorderStyle.FixedSingle;Panel1.Controls.Add(lb1);string name = "";private void label_Click(object sender, EventArgs e){ Label lbl = sender as Label; name = lbl.Name;}
然後在Button2的Click中:
private void button2_Click(object sender, EventArgs e){ Label lbl = Panel1.Controls[name]; if(lbl != null) Panel1.Controls.Remove(lbl);}