【发布时间】:2008-12-08 18:53:40
【问题描述】:
我有一个简单的应用程序,它显示拖到它上面的图片。我希望应用程序根据它显示的图片调整自身大小。下面的代码就是这样做的:
// 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;
它认为我需要一些帮助来改进这一点是相当明显的。随着表格变得越来越复杂,适当尺寸的计算也将变得越来越复杂。 有什么建议吗?
【问题讨论】: