parveenmehta
asked on
Deleting control in runtime
I am adding a label to an image in PictureBox during in run time.
How can i delete it in runtime only if it exists ? I am coding in C#.
Thanks
How can i delete it in runtime only if it exists ? I am coding in C#.
Thanks
ASKER
This is exactly what i have done. I want only one label box displaying at a given time.If user click insert text again then previous lable should be delted and another one should be added.
public void insert_text_Click(object sender, System.EventArgs e)
{
Label lbl = new Label();
lbl.Size=new Size(130,40);
lbl.Text = textBox2.Text;
lbl.BackColor = Color.White;
lbl.Location = new Point(336, 150);
lbl.MouseDown += new MouseEventHandler(lbl_Mous eDown);
lbl.MouseMove += new MouseEventHandler(lbl_Mous eMove);
if(pictureBoxEx1.Controls. Contains(l bl))
{pictureBoxEx1.Controls.Re move(lbl);
}
pictureBoxEx1.Controls.Add (lbl);
insert_text.Enabled=false;
}
public void insert_text_Click(object sender, System.EventArgs e)
{
Label lbl = new Label();
lbl.Size=new Size(130,40);
lbl.Text = textBox2.Text;
lbl.BackColor = Color.White;
lbl.Location = new Point(336, 150);
lbl.MouseDown += new MouseEventHandler(lbl_Mous
lbl.MouseMove += new MouseEventHandler(lbl_Mous
if(pictureBoxEx1.Controls.
{pictureBoxEx1.Controls.Re
}
pictureBoxEx1.Controls.Add
insert_text.Enabled=false;
}
ASKER
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pictureBox1.Controls.Remov
if not, whatever container you have it in you will need to access the Controls collection and remove it.