[英]How to resize a PictureBox while maintaining its Aspect Ratio
I have a Windows Forms application where I let the user resize a PictureBox. 我有一个Windows窗体应用程序,我让用户调整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?
我知道如何通过mouseDown,mouseMove和mouseUp事件正常调整图片框的大小,但是如何确保它保持纵横比?
Change SizeMode = Zoom
on the PictureBox
. 更改
SizeMode = Zoom
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. 您可能不需要的唯一副作用是,如果您足够大地增加表单的大小,它也会使图像大于原始图像,从而导致图像模糊。
You can make the IMAGE inside the PictureBox to keep it aspect ratio... using SizeMode = Zoom 您可以在PictureBox中创建IMAGE以保持其纵横比...使用SizeMode = Zoom
The PictureBox can be resized to any size, but the image will kept its aspect ratio within the PictureBox boundaries. PictureBox可以调整为任何大小,但图像将保持其纵横比在PictureBox边界内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.