gpt4 book ai didi

c# - 从 TableLayoutPanel 单元格获取高度和宽度

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:14 25 4
gpt4 key购买 nike

我需要找出放置按钮的单元格的高度和宽度。 RowStyles 和 ColumnStyles 都设置为 Percent,TableLayoutPanel 的 Dock 为 Fill,按钮的 Dock 也是如此。

TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(button1);
int width = tableLayoutPanel1.GetColumnWidths()[pos.Column];
int height = tableLayoutPanel1.GetRowHeights()[pos.Row];

但它不起作用。我收到以下错误:

"An unhandled exception of type 'System.IndexOutOfRangeException' occurred in < my program name.exe >

Additional information: Index outside of bounds of array."

我认为问题是因为我的应用程序适用于 .NET 3.5(并且不能再更高)。
那么如何获取单元格的高度和宽度呢?

最佳答案

我认为问题在于 button1 不在 tableLayoutPanel1 中。所以调用 tableLayoutPanel1.GetCellPosition(button1) 导致 (-1,-1) 和int width = tableLayoutPanel1.GetColumnWidths()[-1]; 绝对会抛出 IndexOutOfRangeException

关于c# - 从 TableLayoutPanel 单元格获取高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28558496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com