c# - 在 Windows 窗体中获取 TableLayoutPanel 单元格的高度和宽度

标签 c# .net winforms cell tablelayoutpanel

在 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/

相关文章:

C# 将较大的方法分成两个线程

c# - 如何打印字符串

c# - WIA Twain 支持 C#

c# - 群集重叠圆圈?

c# - ASP.NET Web API - 如何更改 XML 对象图中的最大项数

c# - "Translate"属性名转换成可读的名字

c# - 绕过 Windows 兼容性链接目录

c# - string.IsNullOrEmpty() 似乎不适用于类中类中的字符串

winforms - 最佳实践 UI 指南?

C# dt.Compute() 在某些乘法上不能正常工作