You could simply arrange the instance of
PictureBox
in a loop, the way you want. A matrix would be a nested X-Y loop, and so on.
However, you may want the images to flow as you resize the window, preserving those gaps. Then you can use the class
System.Windows.Forms.FlowLayoutPanel
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel%28v=vs.110%29.aspx[
^].
How to preserve the 5-pixel gaps then? You need to put each
PictureBox
in a fixed-size panel 5 pixels taller and wider. And then you can use the property
Padding
on that panel to create some gaps, say, on right and bottom. (Then you may need to make the rightmost panel of different
Width
and
Padding
, to unwanted avoid extra gap.) And then drop those bigger panel instances in a flow panel, which will auto-arrange the layout. It's just a matter of trying, to see what would you prefer and evoke further ideas.
You also need to know how to add a control in code. Here is how:
Dim someChildControl As Control =
Dim someOtherChildControl As Control =
Dim someParentControl As Control =
someParentControl.Controls.Add(someChildControl);
someOtherChildControl.Parent = someParentControl;
I also have another, universal idea. Create a prototype of what you want to see using the designer, build/run the project. And then, look at the auto-generated code to see how it was implemented in code. After you understand it, use the technique in your own code.
—SA