C# change location of controls inside FlowLayoutPanel
-
15-11-2019 - |
質問
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.
解決
You could also set the top margin of the label to (containerHeight-labelHeight)/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.
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);