Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a PictureBox while maintaining its Aspect Ratio

Tags:

c#

.net

winforms

I have a Windows Forms application where I let the user resize a PictureBox. But it's pretty useless because it does not maintain its aspect ratio as the user makes it smaller or larger.

How can I do this? I know how to resize a picturebox normally with mouseDown, mouseMove and mouseUp events, but how to make sure it keeps its aspect ratio?

like image 292
uSeRnAmEhAhAhAhAhA Avatar asked Mar 22 '14 14:03

uSeRnAmEhAhAhAhAhA


2 Answers

Change SizeMode = Zoom on the PictureBox. That will keep the aspect ratio for your image.

The only side-effect you may not want is that it will also make the image larger than the original, if you increase the size of the form enough, resulting in a fuzzy looking image.

like image 54
Grant Winney Avatar answered Oct 03 '22 10:10

Grant Winney


You can make the IMAGE inside the PictureBox to keep it aspect ratio... using SizeMode = Zoom

The PictureBox can be resized to any size, but the image will kept its aspect ratio within the PictureBox boundaries.

like image 38
Romias Avatar answered Oct 03 '22 09:10

Romias