Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
889 views
in Technique[技术] by (71.8m points)

c# - How to set FlowLayoutPanel contents at Center of Form

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.

max

But when I try to resize or restore down the buttons wont at middle anymore because of manually set of padding.

min

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 of FlowLayoutPanel to true
    • Set AutoSizeMode of FlowLayoutPanel to GrowAndShrink
    • Set Anchor property of FlowLayoutPanel to Top, Bottom
  • Use a TableLayoutPanel for hosting the FlowLayoutPanel
    • Use a single Column and a single Row in TableLayoutPanel.
    • Set Dock property of TableLayoutPanel to Bottom.

This way, when you add or remove images dynamically, all images will be shown at bottom center of the form.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...