469,644 Members | 1,696 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

autosizing picture in picturebox

DjPal
15
Hi,
I have a picturebox in C#, visual studio 2008. when a picture is sent into the picturebox, the image is does not resize to the size of the picturebox. I tried the "behaviour options" in visual studios properties but alas no luck.
Is there a way around this?

Thank you.
Mar 18 '10 #1

✓ answered by tlhintoq

Take a look at the PictureBox in the MSDN
http://msdn.microsoft.com/en-us/libr...es(VS.71).aspx

It has a property called "SizeMode"

4 8115
tlhintoq
3,525 Expert 2GB
Take a look at the PictureBox in the MSDN
http://msdn.microsoft.com/en-us/libr...es(VS.71).aspx

It has a property called "SizeMode"
Mar 18 '10 #2
Sfreak
64
I think this can solve your problem (solved mine)

Expand|Select|Wrap|Line Numbers
  1. displayed_image.Image = original_image.GetThumbnailImage(172, 163, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
  2.         public bool ThumbnailCallback()
  3.         {
  4.             return true;
  5.         }
  6.  
Thumbnail the image and resize it.
Mar 18 '10 #3
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.


Instead of hard coding sizes of 172 x 163 why not make it more dynamic and responsive. Not to mention a bit more re-usable.

If you are going to resize the image to fit the picturebox, then do that.
Expand|Select|Wrap|Line Numbers
  1. Image New image = original_image.GetThumbnailImage(myPictureBox.Width, myPictureBox.Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero)
  2.  
Now it works regardless of picturebox size. If you put this in the SizeChanged event handler it will even update as you resize the form.
Mar 18 '10 #4
Sfreak
64
Sure! thanks tlhintoq

Its also a nice solution

Sorry for the unformatted text... im new here

I Hope I could help
Mar 19 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Pavan Arise | last post: by
3 posts views Thread by Rado | last post: by
2 posts views Thread by Geoff Turner | last post: by
5 posts views Thread by GoGs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.