Changing the z order of controls on a window at runtime

I was looking for an answer to this and have seen everything from it cannot be done to buy an MBS plugin. The forum has a lot of 4-5 year old posts and Xojo seems to have changed drastically since then. My 2 questions are:

  1. I right now create controls dynamically, they all need to be on the bottom so they don’t overlap the static UI. I need to through code force this behavior.

  2. I am adding controls in the editor but they seem to be ordered based on when they were added… Is there a way to move the z-order without deleting controls and re-creating them in the correct order?

I really don’t want to spend money on 3rd party plugins, thank you for your time and input!

Paul,

High level speaking - I have done this on a canvas where I am drawing widgets. I have a class type array that I use to hold said widget information. I then have a function that controls the z-order of how I draw to this canvas as the last drawing is what stays on z-order (os x). Generally this is how I control this scenario. Also i use container controls and I also can control them through an array or just visible = true/false.

Hopefully this helps as a starting point for you and also feel free to add more details to this conversation.

  • Mike

I am still learning how to use Canvases, they seem to be really powerful, are there any resources you used to learn about them besides the obvious documentation manual? Thank you for your reply!
I still think it is weird that it feels like a workaround for z-order instead of what most other software does which is just adding a layer integer (items on the same layer are then layered by creation order).

In Xojo, you’re not supposed to overlap controls. Most of us don’t need Z-Order as a property because we follow the “don’t overlap” advice that comes straight from Xojo. As far as has anyone done this, I know @anon20074439 was doing extensive declares work for Windows overriding the Z-Order some time ago.

2 Likes

Paul, are you developing for mac/windows/linux or crossplatform?

If you want to alter the ordering of controls at design time, you can use these buttons at the top of the editor:

image

As for runtime, if I can help, that really depends on the platform you are going to use.

1 Like

In Xojo, you’re not supposed to overlap controls. Most of us don’t need Z-Order as a property because we follow the “don’t overlap” advice that comes straight from Xojo.

This is something I did not know, I guess canvas is the only way then? Or do containers work like Canvases? Basically I have a bunch of static “floating” UI elements and the underlying board with object/controls on them. Much akin to mobile interfaces (since this will ultimately move to android as well I want the interfaces to be similar).

That answers my #2 question!! Thank you!
Sometimes I can’t get edges to line up perfectly so overlapping makes it easy. Now it is just figuring out at runtime since I add controls dynamically and I am not sure if I can avoid overlapping without changing my design to fit Xojo’s limits.

It kind of depends. Canvas is meant for drawing, so if you’re drawing a bunch of custom controls one single Canvas would be the way to go. If you’re using native controls, finding an alternate solution is the direction I personally would take.

1 Like

It really depends on what you’re trying to achieve, its a bit hard to understand what you want to do through text and the ultimately the best suggestion to achieve what you want. Maybe a screenshot or a drawing would help.

If you want the controls to always stay “at the back” then add a container “at the back” and AddControl to that, this will keep the controls on a similar “layer” to others on the container control being behind controls that are “in front of” the container.

Keep an eye on the red border when you’re moving controls around, this is the parent, and this will become the “local group” for the forward/backward buttons. If you move a container forward/back with controls on it, they will move with the container en masse.

1 Like

Just using this to give credit for the 2 people with answers (Julian/Tim):

Paul, are you developing for mac/windows/linux or crossplatform?

If you want to alter the ordering of controls at design time, you can use these buttons at the top of the > editor:

image

As for runtime, if I can help, that really depends on the platform you are going to use.

It kind of depends. Canvas is meant for drawing, so if you’re drawing a bunch of custom controls one
single Canvas would be the way to go. If you’re using native controls, finding an alternate solution is the
direction I personally would take.

It really depends on what you’re trying to achieve, its a bit hard to understand what you want to do through text and the ultimately the best suggestion to achieve what you want. Maybe a screenshot or a drawing would help.

If you want the controls to always stay “at the back” then add a container “at the back” and AddControl to that, this will keep the controls on a similar “layer” to others on the container control being behind controls that are “in front of” the container.

Keep an eye on the red border when you’re moving controls around, this is the parent, and this will become the “local group” for the forward/backward buttons. If you move a container forward/back with controls on it, they will move with the container en masse.