Determine the Cell of a Table Layout Panel Controls are Contained in

拥有回忆 提交于 2019-12-11 18:15:06

问题


I am working on a project in VB.Net, and am using a Table Layout Panel to allow for multiple windows to be open side by side with one another.

The issue I am dealing with right now is figuring out exactly which Column of the Table Layout Panel components are placed in at run time.

For example, let's say I have two Windows open, with 3 Columns. So there are controls in Columns 1 & 2, and Column 3 is empty. If I close the Window in Column 1, I want to detect the Column it was in, so that I can shift the Window in Column 2 over to Column 1. I'm trying to do this so I can resize the windows based on how many windows are being opened side by side.

However I can't seem to find a way to determine exactly while Column is the 'parent' Column. The parent container is the Table Layout Panel itself, but I don't know how to get the information I am looking for.


回答1:


You can determine the position of a child control inside a TableLayoutPanel using its GetPositionFromControl() method, which will return a TableLayoutPanelCellPosition structure, identifying the Column and Row of the cell that a control is occupying:

Dim Position As TableLayoutPanelCellPosition = 
                TableLayoutPanel1.GetPositionFromControl([ControlName]) 

Position reports Position.Column and Position.Row as Integer values.

You can also detemine which child control is occupying a specified position, using the GetControlFromPosition() method:

Dim MyControl As Control = TableLayoutPanel1.GetControlFromPosition(0, 0)


来源:https://stackoverflow.com/questions/50411956/determine-the-cell-of-a-table-layout-panel-controls-are-contained-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!