Picture Boxes

J

Jerry S

Hi

I wonder if someone can help with this, because there's something I'm
not understanding right.

I've got a List Array of PictureBoxes.

If I call PictureBoxListArray.Clear(), and then MainForm.Invalidate(),
the picture boxes remain visible on the form.

I'm not sure why!

What's the best way to get rid of them?

I've tried ((PictureBox) PictureBoxListArray).Dispose() - for each
of the picture box objects, but that seems to cause problems...

Any advice greatly appreciated!

Thanks.

Regards,

Jerry
 
N

Nicholas Paldino [.NET/C# MVP]

Jerry,

The reason for this is that you are not removing the picture box
controls from the control that is hosting them. Basically, if the boxes are
on the form, you have to do the following for each picturebox:

- Call the Remove method on the ControlCollection instance returned by the
Controls property.
- Remove the reference to the control from the PictureBoxListArray.
- Call Dispose on the control (if you don't need them anymore).

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top