R – Maintain a controls Aspect Ratio on Resize


I have a panel control with a picture box in it. How can I maintain the aspect ratio of the panel control when Resizing the form it's on?

Best Solution

You'll need to store off the aspect ratio somehow, whether it's something known to you at design time or if you just want to calculate it in the constructor of the form after InitializeComponent(). In your form's Resize event, you'll just need to set the size of the Panel to be the largest rectangle at that aspect ratio that fits within the ClientRectangle of the form.