Use a panel. Then add your pictureBoxes to the panel. Make sure you set AutoScroll = true.
public class Form1 : Form
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Panel panel1;
private string _dir = @"C:\img";
private string _pat = "*.bmp";
public Form1()
{
InitializeComponent();
LoadPictureBoxes();
}
private void LoadPictureBoxes()
{
int count = 0;
foreach(string path in Directory.GetFiles(_dir,_pat))
{
PictureBox pb = new PictureBox();
pb.Image = new Bitmap(path);
pb.Height = 100;
pb.Width = panel1.Width - 5;
pb.Left = 0;
pb.Top = count * 100;
panel1.Controls.Add(pb);
count++;
}
}
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(505, 659);
this.panel1.TabIndex = 0;
this.panel1.VerticalScroll.Enabled = true;
this.panel1.AutoScroll = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(505, 659);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}