J'ai une application simple qui montre des images traînées sur elle. J'aimerais que l'application se redimensionne en fonction de l'image affichée. Le code ci-dessous fait juste cela:Vous cherchez une meilleure façon de changer la taille du formulaire parent
// 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;
Je pense qu'il est assez évident où j'aimerais avoir de l'aide pour améliorer cela. Comme les formes deviennent plus compliquées, le calcul de la taille appropriée le serait également. Suggestions?
Je n'étais pas au courant des trucs AutoSize ... cela semble certainement être la meilleure façon d'y aller. –