How to change paint order of container controls

Hi,
when I place several instances of my class based on containercontrol
they are painted to screen in the order they are instantiated of course.
So the “younger” instances always will overlap the “elder”.
I would like to know where this order is stored to get a chance to rearrange this order.

To be able to manipulate each instance I store them in an array.
Probably I could use this array to manage the paint order myself
But I don’t know how to begin.

You shouldn’t have overlapping controls. What are you trying to achieve?

The instances of my container control class each contains a label and a canvas with a thumpnail. The user builds as many “labels” he needs an moves them around on screen to arrange them as he likes.

Not a good idea. This will lead to all sorts of fun with flashing etc.

Make one canvas - subclass or on a container. Create a class for your data. Then have the canvas do the drawing of your data objects.

the “flowchart” project in the example/graphics and multimedia folder is a good start for this objects drawing on a canvas.

Thank you for the hints. The ObjectsInCanvas example is really impressive.

In my application I intend to use ordinary controls like label, textarea may be some others within a container control.
The redrawing of these controls couldn’t be controlled by the paint event of a canvas. They do it oneself with a considerable flicker.
The flicker with my approach is just insignificant.
On the other hand a canvas gives the opportunity to control the paint order.

So, is there any chance to control the paint order of container controls embedded in another container control?

As mentioned previously… DON’T DO IT THAT WAY
Create a virtual instance of you objects… by this I mean a class that contains DATA that describes what to draw
and in the PAINT event of a canvas , execute those “instructions” to DRAW the “objects”… Or if more speed is required, use a PICTURE object to draw things, only updating moved or changed objects.

I created an entire Visio like application that worked in this manner. The mouse movements (dragging etc), simply updated the “database”, and redrew the objects that “changed”

This results in ONE object to control (the canvas), and you can manipulate as many “objects” as required, without worrying about creating and destroying instances of controls

add a property to your container control, named “order”
fill that property with an incrementing value when you embed the container in the canvas
also add all the containers in a canvas property
then you should have all you need to get the order you draw them.

No. The initial painting is out of your hands. Of course you can always trigger a paint event afterward with invalidate, but not the initial one.

Controlling event order is a frequent mistake coming from procedural programming.

In an event driven environment such as Xojo, you must write events as separate, self-contained occurrences, which may take place at times that are not pre-determined.

You really want to keep this notion, as you create more and more ambitious programs.

I will not lecture you about moving controls rather than drawings on a single canvas. This has already been done. On Mac, you are probably safe stacking controls. The system actually knows pretty well how to deal with it. On Windows, it is a sure way to flicker.

Thank you, Michel, that’s the information I needed to understand the problem I have.
Thanks to all of you for your help. Now it’s easier to accord with expectations even though I have to try out a lot of details and I think I may ask again.