In my Xojo application I dynamically create Canvas objects. I want these to stack in a specific order. However, I can't seem to get the images to stack the way I want. How can I specify the order in which the images appear?
3 Answers
I assume you mean that you have a Control array declared in a Window, i.e. you have a Canvas control in the Window, with its Index set to 0. And you add new Canvas Control instances by using the new
operator.
I believe that the order in which these Controls appear in the array is also the order (or its reverse) in which they get drawn. But that should be obvious to you, I'd think. So I guess you're doing something more that causes your difficulty, but you haven't communicated that yet.

- 11,045
- 8
- 74
- 149
-
You are correct in how I create them with the new operator. They are actually two different control arrays. I tried bringing the image array I want to appear on top to the front in the window editor but it still doesn't work. – Floyd Resler Oct 04 '16 at 12:40
If you are trying to stack/tile canvas objects then you might be better of trying to work the various images inside the canvas.paint event. Stacking of controls will almost always guarantee poor performance and flicker (especially in Windows).
There might be valid reasons for doing what you're doing, but I suspect that it's not the best Xojo way. Without more info it's hard to say.
Think of the canvas object in the say that old animations were done. You draw the background, then you draw the objects in the next layer up, and then the next layer and so on. This is remarkably fast (we created a full fledged word processor that does this with insertion prompt, etc).

- 1,299
- 6
- 8
Late to the game, but you might have more control of your images by inserting them as pixmapShapes in a Group2D object in the Objects of a Picture in a single Canvas.Background. An example might look like:
dim pixmapA as new pixmapShape(pictureA)
dim composite as new group2D //behaves much like an array
composite.append(new pixmapShape(pictureB)) //lacks variable name (see pixmapA)
composite.item(0).rotation=.9 //but still editable if you know its index
composite.append(pixmapA) //on top and still addressable as 'pixmapA'
pixmapA.fill=50 //e.g. changed transparency
//add this group to a picture (lets suppose 'myPicture' exists)
myPicture.objects=composite
myCanvas.Backdrop=myPicture
//or you can paint to graphics
myPicture.graphics.drawObject(composite)
The only gotcha with object2D is that its coordinate system has 0,0 in the center of an object, not the top, left used everywhere else.
Upon rereading, if you must have separate canvases to respond to events (e.g. they are custom controls, this might not be workable)

- 81
- 1
- 3