Reputation: 387
I have a Picture boxes inside a parent label and I want to be able remove them all. I tried MyLbl.controls.clear()
and that didn't do anything, I did not get an error, just nothing happened. I tried giving them tags and looping through all controls In the form looking for the tag but it never found them.
Is there a way to do this?
Upvotes: 0
Views: 438
Reputation: 1356
WinForms Label control does not allow adding child controls by default using designer, even if picture boxes appear above the label. Unless you explicitly said MyLbl.Controls.Add MyPicture1
, the picture box is actually child of your Form
or some other container.
You can check this by going to View > Other Windows > Document Outline in Visual Studio when a form designer is open.
In case picture box is child of a form, you'll have to remove related controls from form's Controls
collection.
But to simplify this, you can just add a GroupBox
or Panel
to your Form, and place PictureBox
es there. Then, you can do MyGrpBox.Controls.Clear()
.
Upvotes: 1