TableLayoutPanel's Control Columns properties

一世执手 提交于 2019-12-13 13:27:25

问题



I've noticed that every control added to the TableLayoutPanel is given "Column" and "Row" properties. How can I get access to these properties through code?
thanks:)


回答1:


These properties only exist in the Properties Window, magic provided by the IExtenderProvider interface. They don't exist at runtime. Extended properties are:

  • ColumnSpan. Runtime: GetColumnSpan() and SetColumnSpan()
  • RowSpan. Runtime: GetRowSpan() and SetRowSpan()
  • Row. Runtime: GetRow() and SetRow()
  • Cell. Runtime: GetCellPosition() and SetCellPosition()
  • Column. Runtime: GetColumn() and SetColumn()

Obviously TLP was highly optimized to be used from the designer. It's kinda of a pain at runtime.




回答2:


Although the properties designer shows the row and column as properties of the added control thay are set programatically using a method on the table layout panel itself (SetColumn(control, index) and SetRow(control, index)).

This pattern of behaviour is similar the tool tip component and the error component.




回答3:


Go here.

This properties are added by means of "extending properties", something that other controls like ToolTip uses.




回答4:


// Create TableLayoutPanel TableLayoutPanel tlp = new TableLayoutPanel();

// Set the BorderStyle to 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);

for more check this

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



来源:https://stackoverflow.com/questions/4948453/tablelayoutpanels-control-columns-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!