Control Layering With Dynamically Created Controls

Hey all,

When creating controls in the IDE, you can set the “layer” position of controls with these buttons below:


If I create a control dynamically in code, how can I do this? I’ve not been able to find a property that determines the layering order of controls. I have an instance where I have a canvas control where sometimes I want to make the canvas completely transparent and bring up an HTML Viewer behind it. I want the HTML Viewer to be behind the canvas as there’s a number of custom mouse related commands that the canvas has that can’t be implemented on the HTML viewer.

Please tell me this is not something I can only do in the IDE…



I believe the last added control will be the top-most item.
But that might not be true on all platforms.

That is correct and reflects what I am seeing. How then do I change that order in code. I can do it in the IDE, but I want to do it in code.

This might help:

Thanks. But I need it to be XPlat not just Mac. So looks like there’s no “built-in” way to do this?

Desktop doesn’t have a RemoveControl method unfortunately.

What if you move the control out of the Window by setting left and top to -1000.
Set the control.visible to false

Then add another identical control to your window. That last added control will then be the control with the highest z-order.

Control.Close should do that.


Actually, I can add/remove it at will utilizing control sets.

The issue I have is that when I want to show the HTML viewer, it’s showing an MJPEG stream. Just hiding that control will continue to consumer bandwidth as the MJPEG stream isn’t stopped. So I figured I would just create and close the control as needed. But I need it to remain BEHIND the canvas.

And obviously there is a property setting somewhere that sets the Z order. But it appears Xojo doesn’t allow that property to be set at run time - only in the IDE.

Forgot about that method. :slight_smile:

Can’t you use the parent property of the control? Assuming the canvas is the same size as the HTMLviewer, just use Canvas1.Parent = HTMLViewer1 which will change the z-order of the controls.


Oh maybe I did it backwards. I made the HTMLViewer the Parent of the Canvas…

That did it, Wayne! Thank you for your sage advice! :smiley:

1 Like