Stack ContainerControls

During runtime my small desktop app (osx) creates some containercontrols (called “ding” ) in a window. I can move them and make new "ding"s. Somewhat like a stack of playing cards.

After moving a “ding” I want it to be on top of the stack and not in its current position behind other "ding"s.

How do I do that?

How are these CCs being added? Programmatically? Or have you added them within the IDE?

If programmatically, and you’re storing them in, say, an array, you can re-arrange the order of the array and then refresh the window to force them all to redraw in the new arrangement. That would be the best way, I would think. If you’ve added them within the IDE I’m not sure how to do that at run-time.

They are made programmatically. The contents of the CC’s are to be stored in a database so they can be completely rebuild. But I hoped for a simpler solution.

Well, somehow you have to control the drawing order of the controls. It’s based on how they were added – first ones are on the bottom, later ones on the top. So you need to change that if you want to re-arrange them.

I once had to do something similar (though I cant recall exactly how); I created one large canvas that was sized appropriately, I then created several smaller canvases within it but they were set to invisible so they were never drawn.

Depending on the event, they were all moved into position and /or had their images changed, after this point the paint event for the canvas was initiated and it looped over all these canvases in the relevant order, using them to draw their graphics onto the main canvas, creating several layers of images being drawn over each other…

if you’re literally trying to display an image and layer them (exactly like a pack of cards) then the above method may be practical. There was no real purpose for me to use a canvas control myself either, since I didn’t need user interaction from those parts (a sub classed picture object probably would have been more efficient)

Really depends what you need to display /layer & how /why etc (i wouldn’t have though container controls would be appropriate for stacking on top of each other, at least with the thought of playing cards concept in my mind)

If you only want to see the top “ding” then just make all those below invisible. This could be easily controlled by adding a computed property to each “ding” which would hold a reference to the covering “ding”.

If you want to stack a deck of cards by layering them showing the cards underneath then you should use a canvas & draw the cards on top of each other.

If your target may be windows do not layer canvases on top of canvases.


solved: the simplest solution was redrawing the “ding” that i want on top.