Loading a control within a control in Visual Basic

Started by Robert Collins, November 30, 2005, 04:51:59 PM

Previous topic - Next topic

Robert Collins

Example: At design time I place a PictureBox control on a VB form (call it Picture1) and then I place another PictureBox control (Picture2) inside Picture1. VB treats Picture2 as a child of Picture1. This means that when I move Picture1 around the surface of the form Picture2 will follow along with the move and keep it's realitive position within Picture1.

This I have no problem with and I do it quit alot for designing special graphical applications.

Now, at design time, I want to make Picture2 an array of picture boxes so I will give Picture2 an Index of 0.

During Run time I want to create (using the Load command) a second Picture2 control so I will use the following: Load Picture2(1).

The new PictureBox is created but with one problem. It is not a child of Picture1 and it is outside the perimiters of the parent control (Picture1).

Is it possible to do what I want?

Robert Collins

OK. I see no one has replied to this topic but that's OK since I have found a way to do this using some API's and subclassing in VB.

zooba

Shouldn't need to do any subclassing, a simple 'SetParent' call should do it.

Just having a quick play, if you're using VB6, you can do this:

Set Command1(1).Container = Picture1

This doesn't work with the Parent property. VB6 tends to interact with the API quite well in most cases though, so SetParent probably won't cause any trouble.

Robert Collins

Quote from: zooba on December 11, 2005, 11:41:32 PM
Shouldn't need to do any subclassing, a simple 'SetParent' call should do it.

Just having a quick play, if you're using VB6, you can do this:

Set Command1(1).Container = Picture1

This doesn't work with the Parent property. VB6 tends to interact with the API quite well in most cases though, so SetParent probably won't cause any trouble.

Yes! That is by far much much simplier. I never gave thought to doing that.

Thanks, zooba! Exactly what I was looking for.