TableLayoutPanel的控制列属性
我注意到添加到TableLayoutPanel的每个控件都有“Column”和“Row”属性。 如何通过代码访问这些属性?
谢谢:)
这些属性仅存在于IExtenderProvider接口提供的属性窗口中。 它们在运行时不存在。 扩展属性是:
- ColumnSpan。 运行时:GetColumnSpan()和SetColumnSpan()
- 行跨度。 运行时:GetRowSpan()和SetRowSpan()
- 行。 运行时:GetRow()和SetRow()
- 细胞。 运行时:GetCellPosition()和SetCellPosition()
- 柱。 运行时:GetColumn()和SetColumn()
显然,TLP经过高度优化,可供设计师使用。 这有点像运行时的痛苦。
虽然属性设计器将行和列显示为添加的控件的属性,但是使用表布局面板本身上的方法(SetColumn(control,index)和SetRow(control,index))以编程方式设置。
这种行为模式类似于工具提示组件和错误组件。
去这里
这些属性是通过“扩展属性”添加的,这是ToolTip
等其他控件所使用的。
//创建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);
更多检查这个