I have a PictureBox control on a form that displays a bitmap. However,
the bitmap rarely matches the size of the PictureBox. The different
SizeMode properties don't really do it for me. In one case, it changes
the size of the PictureBox itself, making it larger than the form. In
another, it scales the image to the wrong aspect ratio.
What's the best way to rescale this image at the proper aspect ration
inside this PictureBox?
Lee Crabtree
You cannot do this correctly with a PictureBox. The PictureBox is a
ridicuously easy control to replace however and it could be done based on my
article on how to display an image in it's original aspect ratio using a
transform.
See the GDI+ FAQ for details.

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
>I have a PictureBox control on a form that displays a bitmap. However, the
>bitmap rarely matches the size of the PictureBox. The different SizeMode
[quoted text clipped - 6 lines]
>
> Lee Crabtree
Lee Crabtree - 26 Apr 2006 16:33 GMT
I've read your GDI+ FAQ in the past, and it was extremely useful.
Actually, the app I'm writing is a rewrite of one I wrote a while back
in which I bastardized a few of your techniques. I'm trying to do it
more gracefully this time.
Lee Crabtree
> You cannot do this correctly with a PictureBox. The PictureBox is a
> ridicuously easy control to replace however and it could be done based on my
> article on how to display an image in it's original aspect ratio using a
> transform.
>
> See the GDI+ FAQ for details.
Ze Luis - 21 Jun 2006 11:27 GMT
> You cannot do this correctly with a PictureBox. The PictureBox is a
> ridicuously easy control to replace however and it could be done based on my
> article on how to display an image in it's original aspect ratio using a
> transform.
>
> See the GDI+ FAQ for details.
See the GDI+ FAQ for details.
Where are they (GDI+ FAQ)???
this links are wrong
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
> What's the best way to rescale this image at the proper aspect ration
> inside this PictureBox?
PictureBoxSizeMode.Zoom (keeps aspect ratio)
<http://msdn2.microsoft.com/de-de/library/system.windows.forms.pictureboxsizemode
(VS.80).aspx>
Markus
Lee Crabtree - 26 Apr 2006 16:36 GMT
Strangely, Zoom isn't included in the enumeration as the docs suggest.
Lee Crabtree
>> What's the best way to rescale this image at the proper aspect ration
>> inside this PictureBox?
[quoted text clipped - 4 lines]
>
> Markus
Markus - 27 Apr 2006 06:18 GMT
> Strangely, Zoom isn't included in the enumeration as the docs
> suggest.
>
> Lee Crabtree
You need .NET Framework v2.0, it's not included in 1.1... sorry I didn't
know that, too.
Markus