C# – Centering Windows Forms Controls inside TableLayoutPanel with Visual Studio Designer

cnetwindows-forms-designerwinforms

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"

Best Answer

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.

Related Topic