Centering Windows Forms Controls inside TableLayoutPanel with Visual Studio Designer

21,181

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.

Share:
21,181
sammarcow
Author by

sammarcow

Application Developer with experience in ASP, .NET , OOP, C#, C++, Java, Windows Servers

Updated on October 02, 2020

Comments

  • sammarcow
    sammarcow over 3 years

    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"