2012-12-05 56 views
14

在Windows窗体中使用TableLayoutPanel。我使用SizeStyles和ColumnStyles作为AutoSize和Percent分别。我需要找出放置特定控件的单元格的绝对高度和宽度。获取Windows窗体中TableLayoutPanel单元的高度和宽度

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。

我需要获得单元像素的绝对大小。

回答

24

由于某些奇怪的原因,微软决定从intellisense隐藏这些功能。

这应该工作作为书面:

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

我不知道这是可能隐藏从智能感知功能,非常感谢! – farukdgn

+0

@farukdgn请参阅[BrowsableAttribute类](https://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute(v = vs.110).aspx) – LarsTech

+0

隐藏函数的要点是什么那里? – farukdgn