As I said in the title center horizontally and verticaly buttons aligns my controls in Visual Studio C# according to form size which I randomly put to see my for clearly ( 751; 469 ) to be exact, it centers the controlls according to that size but my form starts as maximized window as it should be. How can I align the controls as the window maximized?
Asked
Active
Viewed 341 times
-1
-
are u using winforms ? – Kapoor Dec 05 '15 at 07:08
-
@Kapoor yea i am using winforms – Alpay Aydıngüler Dec 05 '15 at 07:15
-
does this serve yr purpose ? http://stackoverflow.com/questions/491399/centering-controls-within-a-form-in-net-winforms – Kapoor Dec 05 '15 at 07:37
-
Well it worked when i changed anchor of them to none, not exactly like in that link but still helped. thank you. if you can put it as answer so i can confrim it. – Alpay Aydıngüler Dec 05 '15 at 08:01
-
Thanks . Glad to know it helped. As an answer I'll add another approach too, so you can explore that option as well. – Kapoor Dec 05 '15 at 08:24
1 Answers
0
Most simple will be to change the anchoring, as mentioned here Centering controls within a form in .NET (Winforms)?
Or
we can also explore TableLayoutPanel
. This is what comes to my mind -
On the main form Control Add a
TableLayoutPanel
with 3Column
and 3Row
, To make a 3x3 matrix. Set itsDock
style toFill
you can configure the width of column & rows in %age so the middle cell of this matrix takes the maximum area, something like this
- Since only one control can be added in a cell, I'll add a panel in the center cell (with
Dock
style set toFill
), & then I'll add controls to this panel. The anchoring of these controls is set to none.
this is how it looks at design time
And it scales pretty well when you maximize the window at runtime, like this
Hope adding table makes it an easy design. Incase of any issues please write me a comment.