TableLayoutPanel子控件位置

编程入门 行业动态 更新时间:2024-10-24 19:18:44
本文介绍了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子控件位置

本文发布于:2023-11-12 01:07:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580073.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   位置   TableLayoutPanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!