Changing control z-order at runtime

I need to change the z-order of canvases created from a control set at runtime. I’ve found a few threads about this, and in one of them (https://forum.xojo.com/t/z-order-again/41380 @Sam_Rowlands mentioned it’s possible on the Mac with some declares involving NSViewSuperview. I’ve looked at the MBS collection and haven’t found the equivalent. My question is, can one change the control z-order with MBS? Mac-only is fine.

You can always get NSViewMBS objects for the controls and remove them from superview and add them to another NSViewMBS.

Thank you for pointing me in the right direction. However, I’m not getting it to work quite right. To explain a bit, I have a container control embedded in a window. In it, I want an existing canvas to always be on “top” even as I add new canvases programmatically using a control set. To do that I’m adding adding new canvas (which is now on top) and then remove the existing canvas and adding it back to the same window, to return it to the top position. Like this

dim win as NSWindowMBS = self.truewindow.NSWindowMBS
dim contentView as NSViewMBS = win.contentView

dim ContainerView as NSViewMBS = grayBackgroundCanvas.NSViewMBS
ContainerView.removeFromSuperviewWithoutNeedingDisplay
win.contentView.superview.addSubview ContainerView, NSWindowMBS.NSWindowAbove, contentView

I thought this would move the canvas above any other objects in the window. Do you see the flaw? Thanks for any help.

I’ve got it working now. The last line should be

contentView.addSubview ContainerView, NSWindowMBS.NSWindowAbove, contentView