A canvas getting a surrounding canvas's size

I have a DesktopCanvas with a transparent png icon on it. This canvas is inside another DesktopCanvas, which has a gradient background. This background gradient changes when the button is pressed.

How can I get the width and height of the outer canvas without calling it by name? Is that canvas considered the inner canvas’s parent, since the inner one is within the bounds of the outer one? If not, is there a way for the inner one to get the properties of the outer one, without knowing the name of that canvas?

What I’m trying to do is this:

My app will not allow button resizing at runtime, but this is a set of buttons I am working with and trying to get the right layout for the UI. It may very well be that I need to resize them, and I may want to re-use these controls in another area of the application, at a different size. But I always want the inner canvas (holding the icon) to be 80% of the size of the outer button, and centered. So I would like to be able to resize the outer button in the IDE, without having to edit the sizes and positions of all the inner buttons manually.

It’ll be its parent, won’t it? Have you tried parent.height?

That was my initial thought. but

me.height = me.Parent.height * .8

Results in the following compile error:

image

and of course, the “.height” part doesn’t autocomplete when I type in me.parent. and hit tab – in fact, nothing comes up when typing a dot after parent and hitting tab. That’s why I’m wondering if the surrounding canvas is considered a parent in the first place.

try

Me.Height = DesktopUIControl(Me.Parent).Height * .8
1 Like

Thanks. That did it!

No problem.

I did expect me.parent to work but as I haven’t used this I’m not sure if it is a bug or regular behavior.

the end result is a decent looking set of transport buttons for the film scanner:

image

(they’re not that fuzzy in the app, that’s on the forum software scaling these up, I think)

This is the expected behavior. Parent is of type Object as it can be a Window, Container, or another UIControl depending on how the UI is constructed. You must cast it to an appropriate class. You should be careful to avoid exceptions before casting and ensure that the Parent property value is what you expect:

if me.Parent isa DesktopUIControl then
  me.Height = DesktopUIControl(me.Parent).Height * 0.8
end if
2 Likes