Reputation: 1709
I have some PictureBox
s (of the same width and height) which I'd like to put in some sort of container so I can vertically and horizontally align them to the center, even if I resize the window.
Which container should I use and how?
Edit:
So, if I resize and shrink the width of the window one card from the 1st row should move to the 2nd (because it has no space for itself), or if I resize and expand the width of the window so that it'll have space for another card, one card from the 2nd row should go back to the 1st.
Also, I want the Panel
that contains the cards to be centered.
Upvotes: 0
Views: 53
Reputation: 35646
FlowLayoutPanel
can wrap controls if doesn't have place for them in current line
flowLayoutPanel1.Anchor =
AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
for (int i = 0; i < 10; i++)
{
flowLayoutPanel1.Controls.Add(new Panel {BackColor = Color.Green, Width = 75, Height = 100, Margin = new Padding(4)});
}
Upvotes: 1
Reputation: 2744
Make a panel Set the anchoring to Top, Left, Bottom and Right (so that it resizes to all direction), add a picture box to it and Set the Dock of picture box to Fill. Now your picturebox will be centered inside the panel when you change the dimnensions
Upvotes: 3