How to: Align and Stretch a Control in a TableLayoutPanel Control

You can align and stretch controls in a TableLayoutPanel with the Anchor and Dock properties.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To align and stretch a control

  1. Drag a TableLayoutPanel control from the Toolbox onto your form.

  2. Drag a Button control from the Toolbox into the upper-left cell of the TableLayoutPanel control. The Button control is centered in the cell.

  3. Set the value of the Button control's Anchor property to Left,Right. The Button control stretches to match the width of the cell.

  4. Set the value of the Button control's Anchor property to Top,Bottom. The Button control stretches to match the height of the cell.

  5. Set the value of the Button control's Dock property to Fill. The Button control expands to fill the cell.

  6. Set the value of the Button control's Dock property to None. The Button control returns to its original size and moves to the upper-left corner of the cell. The Windows Forms Designer has set the Anchor property to Top, Left.

  7. Set the value of the Button control's Anchor property to Bottom,Right. The Button control moves to the lower-right corner of the cell.

  8. Set the value of the Button control's Anchor property to None. The Button control moves to the center of the cell.

See Also

Other Resources

TableLayoutPanel Control (Windows Forms)