This Question is Answered

15 "helpful" answers available (3 pts)
2 Replies Last post: Jul 2, 2008 1:33 AM by Mirror

How to keep the Label control's relative position on the Canvas control?

Jul 2, 2008 12:57 AM

Click to view Mirror's profile Level 1 Mirror 12 posts since
Jul 2, 2008
Hi.
I have a problem about Canvas.
I define a Canvas control and a Label control,
then I add the Label control on the Canvas control,
for example ,
the Label control's position which on the canvas control is "x=2cm, y=3cm",
when change the Canvas control size, I want to keep the relative position of the Label control on the Canvas control?

What should I do?

Thank you for your help.
Click to view carl's profile Curl carl 53 posts since
Oct 17, 2007
1. Re: How to keep the Label control's relative position on the Canvas control? Jul 3, 2008 10:59 PM
Canvas uses absolute positioning, so you'd have to recompute the position yourself. It shouldn't be too hard -- you can just multiply every child's position by the appropriate scale for x & y. (E.g. get the list via .graphical-children, and for each child use .get-xy and .set-xy.)

If you don't need the (x, y) positioning of Canvas, you could consider a Grid, or some other Graphic that lays out its children relative to origins and constraints.
Click to view Mirror's profile Level 1 Mirror 12 posts since
Jul 2, 2008
2. Re: How to keep the Label control's relative position on the Canvas control? Jul 2, 2008 1:33 AM
in response to: carl

thanks a lot , Carl