我有一個簡單的應用程序,顯示圖片拖動到它。我希望應用程序根據它顯示的圖片來調整自己的大小。代碼如下:尋找更好的方式來改變父窗體的大小
// 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;
它認爲這是相當明顯的,我希望有一些幫助改善這一點。隨着表格變得更加複雜,計算適當的大小也會變得更加複雜。 建議?
不知道AutoSize的東西...當然,這似乎是最好的方式去這裏。 – 2008-12-09 20:47:10