Canvas1.Parent = Canvas2

I want to add Canvas objects to another Canvas at runtime. I have no clue how to do this.
Because when a add a new instance of a Canvas Subclass, and set it’s parent to a larger Canvas, the small canvas’ parent returns Nil.

Reading this back I see it might be a bit confusing. Let me try to explain this better…

I have two Canvas subclasses:
1 : ViewPort
2 : ClipControl

I want to embed dynamically generated ClipControl instances into the ViewPort.
I want to use a canvas as the ViewPort so I can play around with scrolling the canvas using the ViewPort.Scroll method.
The reason I use a canvas for the ClipControl is to be able to draw that control’s User Interface.

Does anybody have an idea of what the best approach is? Or why the ClipControl.Parent cannot be set to ViewPort?

Got it!

I still don’t know why a Canvas.Parent cannot be set to another Canvas. But I got a workaround.

Instead of using a Canvas for the ClipControl I used a ContainerControl.
All the properties, methods, constants and event handlers I used for the Canvas were compatible with the ContainerControl.

The ContainerControl has a method EmbedWithin. I set the ViewPort to the right parameter of this method and I actually worked.

ViewPort is a Canvas
ClipControl is a ContainerControl

ClipControl.EmbedWithin ViewPort

http://documentation.xojo.com/index.php/New

I don’t quite understand what you mean, Michel.

I did add a new instance if the ClipControl by using “New”
But it didn’t bind it to another Canvas in my initial post. That’s why I went for the ContainerControl instead.

You affect the parent yourself.

dim c as new canvas1 c.parent = Canvas1(0) system.DebugLog c.parent.name

That said, the ContainerControl technique does work fine. It is slightly more complex, that’s all.