获取Windows窗体中TableLayoutPanel单元格的高度和宽度

Bri*_*rij 16 .net c# tablelayoutpanel cell winforms

在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;
Run Code Online (Sandbox Code Playgroud)

上面,我的高度为0. RowStyle的SizeType为AutoSize.同样,我得到了33.33.ColumnStyle设置为SizeType为Percent,Size = 33.33.

我需要获得单元格的绝对大小(以像素为单位).

Lar*_*ech 29

出于某种奇怪的原因,微软决定将这些功能隐藏在智能感知中.

这应该按照书面形式工作:

  TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(button1);
  int width = tableLayoutPanel1.GetColumnWidths()[pos.Column];
  int height = tableLayoutPanel1.GetRowHeights()[pos.Row];
Run Code Online (Sandbox Code Playgroud)

  • 我不知道有可能隐藏intellisense的功能,谢谢! (2认同)