
Runtime adding/removing UserControls from container e.g PictureBox
(Reposting due to getting no answers...maybe nobody knows, or am I being
unclear :-) )
I want to have a scrollable container on a form, to which I can add and
remove a bunch of user controls at run time. I have created my user
controls; I only need to be able to add and remove them from the container.
I haven't been able to do this, at least using a PictureBox as a container.
-If you could change a Container or Parent property on a User Control at
runtime it would work, but for some reason you can't.
-If you could .Add to the PictureBox's ContainedControls collection at
runtime it would work, but for some reason you can't.
-All I have managed to do is .Add the UC's to the Controls collection of the
Form that encloses the PB, and move them so they appear to be in the
PictureBox, but I can't add them to the PictureBox itself (I would like to
do this so they scroll, clip, etc.)
So my questions are
1) Can I do this with a PB, and if so how. So far it seems like the PB can
only accept children at designtime, and at most possibly hide/show them at
runtime. This is no use for me because the user could add any number of
these UC's so I can't prehide them.
2) If I can't, is there some other container control out there that I could
use. I just can't believe there is no way of doing this. It looks like I
could easily do it if I wasn't using UC's, eg by dynamically changing their
Parent property.
Any help much appreciated, I have struggled a while with this one.
(FYI Each of these UC's is a type of small form. The user adds a selection
of these to the container in a desired order and fills them in. When he is
done he presses a button and the app creates a standardized output in a text
file in the correct order based on the contents of these forms. I am using
UC's because each small form has different controls and behavior, accepts
different input, etc. The whole thing would end up looking like a
DataRepeater but with a variety of controls, not just the same one.)