Using a TableLayoutPanel in Windows Forms. I am using RowStyles and ColumnStyles with SizeType as AutoSize and Percent respectively. I need to find out the absolute height a
Microsoft chose to hide the GetColumnsWidths() method from Intellisense (using the attribute EditorBrowsableState.Never) likely because they never really finished implementing the GetColumnsWidths() method. The GetColumnsWidths() method returns an array as long as there is no control in the TableLayoutPanel that has a ColumnSpan value greater than 1. Once that condition exists, you're out of luck and the TableLayoutPanel's GetColumnsWidths() method will return an empty array instead.
An alternative is to use the TableLayoutPanel's ColumnStyles and RowStyles collections--which returns the width/height of each column/row, respectively when the column/row SizeType is Absolute. When it's Percent, the return value is a percentage value; when it's AutoSize, the return value appears to be 0. You can map a percent value to a pixel measurement by taking the total width of the TableLayoutPanel and subtracting the total width of any absolute columns then applying a percent calculation to the remaining pixels if no AutoSize columns are used (same applies to rows).
For some odd reason, Microsoft decided to hide those functions from intellisense.
This should work as written:
TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(button1);
int width = tableLayoutPanel1.GetColumnWidths()[pos.Column];
int height = tableLayoutPanel1.GetRowHeights()[pos.Row];