부모 양식의 크기를 변경하는 더 나은 방법을 찾고
문제
사진이 드래그 된 사진을 보여주는 간단한 응용 프로그램이 있습니다. 응용 프로그램이 표시되는 그림에 따라 크기를 조정하려면합니다. 아래 코드는 다음과 같습니다.
// 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;
이것을 개선하는 데 도움이되는 곳은 상당히 분명하다고 생각합니다. 양식이 더 복잡해지면 적절한 크기의 계산도 더 복잡해집니다. 제안?
해결책
이전 그림과 새 그림 사이의 크기 차이를 계산 한 다음 양식의 다른 모든 것들이 같은 크기를 유지하는 한 양식의 크기를 그 양으로 조정할 수 있습니다.
다른 팁
양식 속성을 볼 수 있습니다.
- 양식
- 양식. AUTOSIZEMODE
PictureBox의 Autosizemode를 설정하는 것과 함께 코드를 작성하지 않고도 원하는 효과를 제공해야합니다.
제휴하지 않습니다 StackOverflow