Click here to Skip to main content
14,668,602 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to figure out how to determine the position of a child control inside of a TableLayoutPanel cell. If I nest a second TableLayoutPanel inside of a cell, the location is calculated properly. If I nest multiple TableLayoutPanel controls, the location (in code) becomes relative to it's parent and not the form. Can anyone show me how to get it's location relative to the form, please? I hope this makes sense. I can give more details if needed.

More Details: I'm creating a form in a designer. Here is a pic
The pic shows the designer view (left) and image (right). I've highlighted the controls in the designer view. This image shows the layout using the native child locations. I know that I could just iterate through the parent locations and add that position to the child positions but I'm hoping there is a better way.

Thank you in advance!
Posted
Updated 6-Jun-13 6:54am
v3
Comments
   
Why would you ever need those coordinates? Everything is done for your convenience. Anyway, it's way too simple. Get it in screen coordinates and then transform to form coordinates, or coordinate system of any other control.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

Here is how I've solved this problem. Still wondering if there is a better option.

As I iterate through each TableLayoutPanel control I determine it's location by:

Point location = panel.Location;
Control parent = panel.Parent;
while (!(parent is DesignerForm)) {
    location.Offset(parent.Location);
    parent = parent.Parent;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100