I've got a simple application that shows pictures dragged onto it. I'd like the application to resize itself according to the picture it displays. The code below does just that:
// Load the picture
Bitmap picture = new Bitmap(s);
// Calculate the size of the main form
this.Size = new Size(picture.Width +
(this.pictureBox.Padding.All +
this.pictureBox.Margin.All +
this.tableLayoutPanel.Padding.All +
this.tableLayoutPanel.Margin.All) * 2,
picture.Height +
(int)this.tableLayoutPanel.RowStyles[1].Height +
(this.pictureBox.Padding.All +
this.pictureBox.Margin.All +
this.tableLayoutPanel.Padding.All +
this.tableLayoutPanel.Margin.All) * 2);
// Display the file.
this.pictureBox.Image = picture;
It think it's fairly obvious where I'd like some help improving this. As the forms get more complicated, so would the calculation of the appropriate size. Suggestions?