14

Hello I am trying to set controls(i.e. Label or Textbox) on center of the form. I need this while i maximize that form. Can i set it statically or dynamically. Anyone have an idea than please tell me asap...

Adam
  • 26,549
  • 8
  • 62
  • 79
user968441
  • 1,471
  • 9
  • 22
  • 48
  • You can use layout controls for this with Dock and achor property – Niranjan Singh May 28 '12 at 15:20
  • 1
    possible duplicate of [C#: Centering controls within a form in .NET (Winforms)?](http://stackoverflow.com/questions/491399/c-centering-controls-within-a-form-in-net-winforms) – JW Lim Jun 06 '14 at 02:39

3 Answers3

32

Place the control on the center and set Anchor property to None.

Adam
  • 26,549
  • 8
  • 62
  • 79
5

you can do it Using the layout control

  1. Add TableLayout Control, Set it’s Dock property to Fill.
  2. Add 1 Row with Size Type style Percent 100%
  3. Add 3 Columns Column1(Size Type – Percent(100%)), Column2(Size Type – Absolute(200px)), Column3(Size Type – Percent(100%)).
  4. Now Add Panel Control to Column2 and Set it’s Dock property to Fill
  5. Add Buttons to this control and set their Size as you want and Set Their Anchor Property to AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top

Reference

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
1

Center aligning a label can be done in Design View. Navigate to 'Properties' there is a setting called 'Autosize' that you have to turn off (set it to false). This allows you to set the width of the label to the width of the page.

Then scroll down in 'Properties' to the setting called 'TextAlign' and set it to 'MiddleCenter'. That should fix the problem.