autosizing picture in picturebox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DjPal
    New Member
    • Dec 2009
    • 15

    autosizing picture in picturebox

    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.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Take a look at the PictureBox in the MSDN


    It has a property called "SizeMode"

    Comment

    • Sfreak
      New Member
      • Mar 2010
      • 64

      #3
      I think this can solve your problem (solved mine)

      Code:
      displayed_image.Image = original_image.GetThumbnailImage(172, 163, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
              public bool ThumbnailCallback()
              {
                  return true;
              }
      Thumbnail the image and resize it.
      Last edited by tlhintoq; Mar 18 '10, 09:29 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        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.
        Code:
        Image New image = original_image.GetThumbnailImage([HIGHLIGHT]myPictureBox.Width, myPictureBox.Height[/HIGHLIGHT], new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero)
        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.

        Comment

        • Sfreak
          New Member
          • Mar 2010
          • 64

          #5
          Sure! thanks tlhintoq

          Its also a nice solution

          Sorry for the unformatted text... im new here

          I Hope I could help

          Comment

          Working...