Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How can I position Controls with TableLayoutPanel?

Additionally the tableLayoutPanel provides several methods to change the position of controls that are already added to the table:

tableLayoutPanel.SetCellPosition(new TableLayoutPanelCellPosition(4,2))

NOTE: Via extender provider on the control itself the SetRow and SetColumn methods can be used.

To determine where a control was place programmatically use the following:

public TableLayoutPanelCellPosition GetPositionFromControl(Control control);||

Absolutely position elements within a TableLayoutPanel

The margin property of control can be used to adjust the distance from the edge of the cell.  If you change the anchor to be Top|Left and change the Margin to be (20,3,0,0) the control will be 20 pixels from the left edge and 3 pixels from the top.

Stretching and aligning elements within a TableLayoutPanel

You can use the anchor property of the control to align to a particular side (e.g. Left will stick it to the Left side).  Using opposing anchors, the control can be stretched.  E.g. Anchor=Left|Right will stretch to fill the width.  The Dock property works in a similar manner.