On May 24, 2006, at 4:03 PM, Chris Griffin wrote:
Has anyone worked out a way to do this? I have a control inside a
ContainerControl. That ContainerControl could be placed in another
control or a window. I need a generic way to work up the 'tree' to
get the global coordinates.
I haven't done anything exactly like that, but you should be able to
combine the coordinates as you walk up through the parent objects. A
control's Left and Top values are local to the parent
ContainerControl, and you access this parent generically using the
Control.Window property. Always check for Nil when accessing this
property, but if it is not Nil then you have at least one more
coordinate to combine.
Something like this (code written in email):
Sub GlobalPosition(c As Control, ByRef x As Integer, ByRef y As Integer)
If c Is Nil Then Return // short-circuit the function on Nil
Dim w As Window = c.Window
x = c.Left
y = c.Top
Do Until (w Is Nil)
x = x + w.Left
y = y + w.Top
If (w IsA ContainerControl) Then w = ContainerControl(w).Window
Else w = Nil
Loop
End Sub
You don't have to use the ByRef... it was just easier for me to write
the example function like that. If it is easier, you could return a
two element array. My personal preference would be to create a
Structure called Point, and return that... except that structures
being returned from functions are not supported yet. :(
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>