I am using flowLayoutPanel
to have relative location controls.
I would like to change the location of control inside the flowLayoutPanel
.
when I say location, I dont mean control1 before control2 or something like that - I mean that if I got 2 controls, lets say label
and comboBox
- the comboBox
's height is 21, the label
's height is 13 and the flowLayoutPanel
's height is 21 also. I want to put the label
in the vertical middle of the flowLayoutPanel
- ((21-13)/2) from top. I dont want something specific for vertical middle I want general solution.
Asked
Active
Viewed 8,330 times
4

Alex Kulinkovich
- 4,408
- 15
- 46
- 50

Ron
- 3,975
- 17
- 80
- 130
3 Answers
4
You could also set the top margin of the label to (containerHeight-labelHeight)/2

Ken Wayne VanderLinde
- 18,915
- 3
- 47
- 72
-
Worked like a charm, I forgot about the margin property. – Ron Feb 17 '11 at 23:22
-
Who da Man? You da Man! This worked great. For anyone else working with this, the margin has to be copied to a variable, modified and then set back. – Brad Bruce Jul 21 '13 at 22:14
2
The flow layout is not going to help: it just arranges all controls in a list, adjusting their position to fit in the panel. You can create subgroups by putting controls in a table within the flow layout, or just use a table for maximum control.

Marco
- 1,346
- 8
- 9
-
How exactly can I set the location of control inside tableLayoutPanel? I cant do it inside tableLayoutPanel too.. – Ron Feb 17 '11 at 23:19
-
I do like the idea of using a TableLayoutPanel - you can set control positions and even dimensions just by setting the dimensions of columns/rows. For a full GUI, it takes a little more planning than placing everything into a FlowLayoutPanel, but I think the rewards are worth it. – Ken Wayne VanderLinde Feb 17 '11 at 23:33
-
0
int cIndex = this.FlowLayoutPanel1.Controls.GetChildIndex(Button1);
int bIndex = this.FlowLayoutPanel1.Controls.GetChildIndex(Button1);
this.FlowLayoutPanel1.Controls.SetChildIndex(Button1, bIndex);
this.FlowLayoutPanel1.Controls.SetChildIndex(Button2, cIndex);

Salah
- 1