在 Windows 窗体中使用 TableLayoutPanel。我将 RowStyles 和 ColumnStyles 与 SizeType 分别用作 AutoSize 和 Percent。我需要找出放置特定控件的单元格的绝对高度和宽度。
TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(button1);
int height = (int)tableLayoutPanel1.RowStyles[pos.Row].Height;
int width = (int)tableLayoutPanel1.ColumnStyles[pos.Column].Width;
上面,我得到的高度为 0。RowStyle 的 SizeType 为 AutoSize。 同样,我得到 33.33。 ColumnStyle 的 SizeType 设置为 Percent,Size = 33.33。
我需要获取单元格的绝对大小(以像素为单位)。
最佳答案
出于某些奇怪的原因,Microsoft 决定对智能感知隐藏这些功能。
这应该像写的那样工作:
TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(button1);
int width = tableLayoutPanel1.GetColumnWidths()[pos.Column];
int height = tableLayoutPanel1.GetRowHeights()[pos.Row];
关于c# - 在 Windows 窗体中获取 TableLayoutPanel 单元格的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13725721/