void DrawAgain()
{
int x = 0;
int y = 0;
int maxH = 0;
foreach (PictureBox p in pics)
{
if (x + p.Width >= 1000)
{
x = 0;
y += maxH;
maxH = 0;
}
p.Left = x;
p.Top = y;
x += p.Width;
if (p.Height > maxH)
maxH = p.Height;
}
}
private void button1_Click(object sender, EventArgs e)
{
pics.Sort((a, b) => a.Width.CompareTo(b.Width));
DrawAgain();
}
private void button2_Click(object sender, EventArgs e)
{
pics.Sort((a, b) => a.Height.CompareTo(b.Height));
DrawAgain();
}