System.Windows.Forms.TableLayoutPanel Class

Represents a panel that dynamically lays out its contents in a grid composed of rows and columns.

See Also: TableLayoutPanel Members


[System.ComponentModel.Design.Serialization.DesignerSerializer("System.Windows.Forms.Design.TableLayoutPanelCodeDomSerializer, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.Designer("System.Windows.Forms.Design.TableLayoutPanelDesigner, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.ComponentModel.ProvideProperty("RowSpan", typeof(System.Windows.Forms.Control))]
[System.ComponentModel.ProvideProperty("Row", typeof(System.Windows.Forms.Control))]
[System.ComponentModel.ProvideProperty("ColumnSpan", typeof(System.Windows.Forms.Control))]
[System.ComponentModel.ProvideProperty("Column", typeof(System.Windows.Forms.Control))]
[System.ComponentModel.ProvideProperty("CellPosition", typeof(System.Windows.Forms.Control))]
public class TableLayoutPanel : Panel, System.ComponentModel.IExtenderProvider


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.


Only controls that have the Control.Visible property set to true participate in the System.Windows.Forms.TableLayoutPanel control's layout computations.



Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions:
Since: .NET 2.0