问题
I have a few Button
controls in a FlowLayoutPanel
, and I want to set them precisely at middle bottom of Form
.
In the image below I set the Button
precisely at middle by setting the FlowLayoutPanel
padding manually by 400 to left.
But when I try to resize or restore down the buttons wont at middle anymore because of manually set of padding.
Is there anything that I can do to set the buttons in middle of FlowLayoutPanel
whenever I try to resize it. I'm following the answer base on
this post to add and remove buttons dynamically.
回答1:
Using a single cell TableLayoutPanel which is suitable for centering the content and an auto-size FlowLayoutPanel you can achieve what you are looking for:
Perform these settings on the controls:
- Add your images to a
FlowLayoutPanel
- Set
AutoSize
ofFlowLayoutPanel
totrue
- Set
AutoSizeMode
ofFlowLayoutPanel
toGrowAndShrink
- Set
Anchor
property ofFlowLayoutPanel
toTop, Bottom
- Set
- Use a
TableLayoutPanel
for hosting theFlowLayoutPanel
- Use a single
Column
and a singleRow
inTableLayoutPanel
. - Set
Dock
property ofTableLayoutPanel
toBottom
.
- Use a single
This way, when you add or remove images dynamically, all images will be shown at bottom center of the form.
来源:https://stackoverflow.com/questions/38824530/how-to-set-flowlayoutpanel-contents-at-center-of-form