Valerie Meunier

Valerie Meunier

  • 947
  • 693
  • 71.3k

how to remove programmatically a label dragged from the toolbox?

Jan 5 2022 10:52 PM

Hi

i dragged a label from the toolbox and i created programmatically another label:

  private void button1_Click_1(object sender, EventArgs e)
        {
            Label lbl = new Label();
            lbl.Text = "dynamic";
            label1.Text = "toolbox"; // from toolbox
            Controls.Add(lbl);
            Controls.Clear();
        }

I want to remove both labels from the form. When i run it, i don't see anything in the form, but when i go to view designer, the label 'lbl' is removed but the label 'label1' (from the toolbox) is still there. How can i remove it as well (i also tried with Controls.Remove(label1))?

Thanks


Answers (3)