See Also: TableLayoutPanel Members
The System.Windows.Forms.TableLayoutPanel control arranges its contents in a grid. Because the layout is performed both at design time and run time, it can change dynamically as the application environment changes. This gives the controls in the panel the ability to proportionally resize, so it can respond to changes such as the parent control resizing or text length changing due to localization.
Any Windows Forms control can be a child of the System.Windows.Forms.TableLayoutPanel control, including other instances of System.Windows.Forms.TableLayoutPanel. This allows you to construct sophisticated layouts that adapt to changes at runtime.
The System.Windows.Forms.TableLayoutPanel control can expand to accommodate new controls when they are added, depending on the value of the TableLayoutPanel.RowCount, TableLayoutPanel.ColumnCount, and TableLayoutPanel.GrowStyle properties. Setting either the TableLayoutPanel.RowCount or TableLayoutPanel.ColumnCount property to a value of 0 specifies that the System.Windows.Forms.TableLayoutPanel will be unbound in the corresponding direction.
You can also control the direction of expansion (horizontal or vertical) after the System.Windows.Forms.TableLayoutPanel control is full of child controls. By default, the System.Windows.Forms.TableLayoutPanel control expands downward by adding rows.
If you want rows and columns that behave differently from the default behavior, you can control the properties of rows and columns by using the TableLayoutPanel.RowStyles and TableLayoutPanel.ColumnStyles properties. You can set the properties of rows or columns individually.
The System.Windows.Forms.TableLayoutPanel control adds the following properties to its child controls: Cell, Column, Row, ColumnSpan, and RowSpan.
You can merge cells in the System.Windows.Forms.TableLayoutPanel control by setting the ColumnSpan or RowSpan properties on a child control.
To set the Cell, Column, Row, ColumnSpan, and RowSpan properties at run time, use the TableLayoutPanel.SetCellPosition(Control, TableLayoutPanelCellPosition), TableLayoutPanel.SetColumn(Control, int), TableLayoutPanel.SetRow(Control, int), TableLayoutPanel.SetColumnSpan(Control, int), and TableLayoutPanel.SetRowSpan(Control, int) methods.
To read the Cell, Column, Row, ColumnSpan, and RowSpan properties at run time, use the TableLayoutPanel.GetCellPosition(Control), TableLayoutPanel.GetColumn(Control), TableLayoutPanel.GetRow(Control), TableLayoutPanel.GetColumnSpan(Control), and TableLayoutPanel.GetRowSpan(Control) methods.
The docking behavior of child controls is the same as other container controls.
The anchoring behavior of child controls in a System.Windows.Forms.TableLayoutPanel differs from the behavior in other container controls. If the value of the child control's Control.Anchor property is set to AnchorStyles.Left or AnchorStyles.Right, the control will be placed against the left or right border of the cell, at a distance that is the sum of the control's Control.Margin property and the panel's Control.Padding property. If both the AnchorStyles.Left and AnchorStyles.Right values are set, the control will be sized to the width of the cell, with the Control.Margin and Control.Padding values taken into account. The behavior for AnchorStyles.Top and AnchorStyles.Bottom anchoring is analogous. For more information, see How to: Anchor and Dock Child Controls in a TableLayoutPanel Control.
If you need a child control to mimic the default anchoring behavior in other container controls, you can adjust the Control.Margin and Control.Padding properties to maintain a constant distance between the control's border and the cell's border.
Setting the values of both the Column and Row properties of a child control to -1 will cause the control to be moved to the first empty cell in the System.Windows.Forms.TableLayoutPanel control. The empty cell will be chosen in a search that proceeds from left to right and from top to bottom. This order is dependent on the culture, so it will behave correctly in right-to-left (RTL) layouts.