4


我注意到添加到 TableLayoutPanel 的每个控件都被赋予了“Column”和“Row”属性。如何通过代码访问这些属性?
谢谢:)

4

4 回答 4

6

这些属性只存在于属性窗口中,由 IExtenderProvider 接口提供。它们在运行时不存在。扩展属性是:

  • 列跨度。运行时:GetColumnSpan() 和 SetColumnSpan()
  • 行跨度。运行时:GetRowSpan() 和 SetRowSpan()
  • 排。运行时:GetRow() 和 SetRow()
  • 细胞。运行时:GetCellPosition() 和 SetCellPosition()
  • 柱子。运行时:GetColumn() 和 SetColumn()

显然,TLP 经过高度优化以供设计人员使用。运行时有点痛苦。

于 2011-02-09T18:07:34.613 回答
3

这里

这些属性是通过“扩展属性”添加的,其他控件喜欢ToolTip使用的东西。

于 2011-02-09T17:54:43.193 回答
3

尽管属性设计器将行和列显示为添加的控件的属性,但它们是使用表格布局面板本身的方法(SetColumn(control, index) 和 SetRow(control, index))以编程方式设置的。

这种行为模式类似于工具提示组件和错误组件。

于 2011-02-09T18:03:41.913 回答
0

// 创建 TableLayoutPanel TableLayoutPanel tlp = new TableLayoutPanel();

// 将 BorderStyle 设置为 Inset tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;

// Grid has two columns
tlp.ColumnCount = 2;

// Grid has two rows
tlp.RowCount = 2;

// If grid is full add extra cells by adding column
tlp.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;

// Padding (pixels)within each cell (left, top, right, bottom)
tlp.Padding = new Padding(1, 1, 4, 5);

// Add TableLayoutPanel to the Forms controls
this.Controls.Add(tlp);

更多检查这个

http://en.csharp-online.net/TableLayoutPanel

于 2011-02-09T17:57:26.003 回答