Tuesday, February 22, 2011

Center a Control on a Form in .NET

It turns out to be very easy to center a control on a .NET form. Just un-anchor the control from any side and it will center from its position. If you just un-anchor from the left and right it will center horizontally, and if you just un-anchor from the top and bottom, it will center vertically. Un-anchor from all sides and it will center on the form.

More info at:

http://stackoverflow.com/questions/491399/c-centering-controls-within-a-form-in-net-winforms

1 comment:

gicalle said...

this is indeed the correct way to do, but you forgot to mention how you center the form in the design view.

the correct steps are:
- select control
- remove anchors
- click in the toolbar on 'format' - 'center in form' and choose vertically and/or horizontally