Click here to Skip to main content
16,022,417 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Sergey Alexandrovich Kryukov 6-Jun-13 12:06pm    
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

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:

C#
Point location = panel.Location;
Control parent = panel.Parent;
while (!(parent is DesignerForm)) {
    location.Offset(parent.Location);
    parent = parent.Parent;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900