How to calculate a control's position relative to the form? lazarus / 31-LCL ---------------------------------------------------------------------- vfclists · 2015-04-27 12:36 How do you calculate a control's position relative to the form, rather than its parent? Does it change when it is placed in a resizable area and moved around? ---------------------------------------------------------------------- Blaazen · 2015-04-27 12:49 Lets say you have Form,  Panel (Left=30, Top=40) and Button on Panel(Left=5, Top=15). Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var aPnt: TPoint; begin   aPnt:=Point(0, 0);   aPnt:=Button1.ClientToParent(aPnt, Form1);   writeln(aPnt.X, ' ', aPnt.Y); end;will write out Code: [Select]35 55 ---------------------------------------------------------------------- vfclists · 2015-04-27 13:58 Quote from: Blaazen on April 27, 2015, 02:49:06 pmLets say you have Form,  Panel (Left=30, Top=40) and Button on Panel(Left=5, Top=15). Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var aPnt: TPoint; begin   aPnt:=Point(0, 0);   aPnt:=Button1.ClientToParent(aPnt, Form1);   writeln(aPnt.X, ' ', aPnt.Y); end;will write out Code: [Select]35 55 If the object is in a resizable panel and resized will the coordinates remain the same, ie does it return the values set at design time or in code, or will it change at runtime? ---------------------------------------------------------------------- Blaazen · 2015-04-27 14:05 Coordinates change at runtime, ClientToParent, ControlToScreen etc. are recursive routines which calculate with actual positions of controls. ---------------------------------------------------------------------- Leledumbo · 2015-04-27 15:42 Quote from: vfclists on April 27, 2015, 02:36:03 pmHow do you calculate a control's position relative to the form, rather than its parent? In the anchor editor, set the form as sibling then configure the anchoring accordingly. ---------------------------------------------------------------------- Blaazen · 2015-04-27 16:02 But if he has button on the panel and panel on the form then anchor editor of the button does not offer form, or is there some trick? ---------------------------------------------------------------------- Leledumbo · 2015-04-27 16:25 Quote from: Blaazen on April 27, 2015, 06:02:18 pmBut if he has button on the panel and panel on the form then anchor editor of the button does not offer form, or is there some trick? Hmm...yes, it's not possible, not even logically correct. There will be conflict if such a schema is allowed. ---------------------------------------------------------------------- Blaazen · 2015-04-27 16:43 I remember, in this situation it writes bunch of messages to the console "*** Invalid resize anchor ***". However, it does not crash