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:
New image showing anchors properly set to "Left, Right" on suspect control
New image showing anchors set to "None"
Select the controls or groups to center. From the Format menu, choose Center in 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.
The TableLayoutPanel control supports the Anchor and Dock properties in its child controls.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With