Runtime adding/removing UserControls from container e.g PictureBox 
Author Message
 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.)



Thu, 08 Aug 2002 03:00:00 GMT  
 Runtime adding/removing UserControls from container e.g PictureBox
Yes.. but I couldn't manage to set the .Container on my user control to my
picturebox for some reason (kept getting Invalid Picture).

But I have just managed to do what I want by adding the optional container
parameter to the Controls.Add method. I was doing Controls.Add progid, name
; just changing to Controls.Add progid, name, container did it. I guess I
should have figured that out earlier but I still don't see why just trying
to create it then setting its parent wouldn't work.

Anyway, thanks!


Quote:
> >-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.

> I'm not sure I understood your question correctly. But I can
> definitely change the container of any control ar runtime using this
> code:

> Set TheControl.Container = TheNewContainer

> Mattias

> __________________________________________________

>      VB+ http://hem.spray.se/mattias.sjogren/
>  Please send questions/replies to the newsgroups



Thu, 08 Aug 2002 03:00:00 GMT  
 Runtime adding/removing UserControls from container e.g PictureBox

Quote:
>-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.

I'm not sure I understood your question correctly. But I can
definitely change the container of any control ar runtime using this
code:

Set TheControl.Container = TheNewContainer

Mattias

__________________________________________________

     VB+ http://hem.spray.se/mattias.sjogren/
 Please send questions/replies to the newsgroups



Fri, 09 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Runtime adding/removing UserControls from container e.g PictureBox

2. Receiving notification about changes(adding or removing ActiveX controls) in the container

3. VB6 : Adding usercontrols using Controls.Add

4. HELP: add/remove menuoptions at runtime

5. Adding and Removing Controls at Runtime

6. Adding and Removing controls during runtime.

7. Pop-Up adding and removing at runtime?

8. Pop-Up adding and removing at runtime?

9. Runtime 0 with usercontrols on Win95

10. Removing entries from Add/Remove list in control panel

11. OCX UserControls talking to other OCX UserControls

12. Adding UserControls to a Panel W/Autoscroll

 

 
Powered by phpBB® Forum Software