TableLayoutPanel子控件位置 [英] TableLayoutPanel child control positions

查看:1205
本文介绍了TableLayoutPanel子控件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何确定 TableLayoutPanel 单元格内的子控件的位置。如果我在单元格中嵌套第二个 TableLayoutPanel ,则会正确计算位置。如果我嵌套多个 TableLayoutPanel 控件,则位置(在代码中)变为相对于它的父级而不是表单。有谁能告诉我如何获得它相对于表格的位置,好吗?我希望这是有道理的。如果需要,我可以提供更多详细信息。



更多细节:我正在设计师中创建一个表单。 这是一张照片

图为设计师视图(左)和图像(右)。我在设计器视图中突出显示了控件。此图像显示使用本机子位置的布局。我知道我可以遍历父位置并将该位置添加到子位置,但我希望有更好的方法。



提前谢谢!

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!

推荐答案

以下是我解决这个问题的方法。仍然想知道是否有更好的选择。



当我遍历每个TableLayoutPanel控件时,我通过以下方式确定它的位置:



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;
}


这篇关于TableLayoutPanel子控件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆