Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering Windows Forms Controls inside TableLayoutPanel with Visual Studio Designer

I have control containers tightly bound to the edge of user controls, evenly spaced on both sides of said user control (child controls are always centered within the parent). Using the designer, I am attempting to add these user controls which that spans all columns within a TableLayoutPanel. I am clicking on the control container and clicking the "Center Horizontally" button on the "Layout" Toolbar. The control will not center.

Why? How do easily center the control?

What I am experiencing does not align with the documentation How to: Align and Stretch a Control in a TableLayoutPanel Control

Problem Control is the 5 Buttons which should be centered among the 2 spanned columns shown:

Buttons are tightly bound to edge of control: Control Layout

New image showing anchors properly set to "Left, Right" on suspect control New image showing anchors

New image showing anchors set to "None" Anchors set to "None"

like image 925
sammarcow Avatar asked Sep 26 '12 20:09

sammarcow


People also ask

How do I center controls in Visual Studio?

Select the controls or groups to center. From the Format menu, choose Center in Form.

What design window do you use to add controls to a form?

The primary way a control is added to a form is through the Visual Studio Designer, but you can also manage the controls on a form at run time through code.

Which control you would select to place the child controls in top left right and bottom using dock property?

The TableLayoutPanel control supports the Anchor and Dock properties in its child controls.


1 Answers

Try setting the Anchor property to None:

dataMasterControl1.Anchor = AnchorStyles.None;

It should center itself from within the TableLayoutPanel cells that contains the control. You may have to adjust the size of the UserControl itself.

like image 65
LarsTech Avatar answered Oct 13 '22 14:10

LarsTech