本文介绍了确定表格布局面板控件的单元格包含在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VB.Net 中处理一个项目,并且正在使用表格布局面板来允许多个窗口并排打开.

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.

例如,假设我打开了两个 Windows,其中包含 3 列.因此,第 1 列和第 1 列中有控件.2,第 3 列是空的.如果我关闭第 1 列中的窗口,我想检测它所在的列,以便我可以将第 2 列中的窗口移动到第 1 列.我正在尝试这样做,以便我可以根据如何调整窗口大小许多窗户并排打开.

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.

但是,我似乎无法找到一种方法来准确确定 Column 是父"列.父容器是Table Layout Panel本身,但是我不知道如何获取我要查找的信息.

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.

推荐答案

您可以确定子控件在 TableLayoutPanel 使用其 GetPositionFromControl() 方法,它将返回一个 TableLayoutPanelCellPosition 结构,标识控件占用的单元格的ColumnRow:

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])

PositionPosition.ColumnPosition.Row 报告为整数值.

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

您还可以使用 GetControlFromPosition() 方法:

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

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

这篇关于确定表格布局面板控件的单元格包含在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:17