Piyush chhabra

Piyush chhabra

  • NA
  • 83
  • 16.7k

Deleting dynamicaly created labels in visual c#

Jun 16 2014 8:57 AM
hello everyone..
 
i have created a windows form app using visual c#.
 in this i have added 10 labels on my form on a button click event.
now on clicking second button, i want 5 out of 10 lables deleted or disappears.
here is my code for making labels.
 
 private void button1_Click(object sender, EventArgs e)
for (int f = 0;  f < l10;  f++)
  {
Color randomcolor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
lbl1 = new Label();  // lbl1 is a object of label class declared outside
lbl1.Text = " ";
lbl1.BackColor = randomcolor;
lbl1.Location = new Point(li[f], 20);
lbl1.Size = new Size(40, 20);
this.Controls.Add(lbl1);
   }
 }
 
now how shoud i code in button2 click event..
private void button2_Click(object sender, EventArgs e) 
{
     ???????????????????????????????????
 
PLEASE HELP..!! 
 
 

Answers (1)