VB.NET 2005 picturebox:  resizing and retaining aspect ratio

Posted on 2007-07-23
Last Modified: 2010-05-18
Hello.  I have a VB.NET 2005 picturebox to work with.  I also have several images that vary in size.  When an image is loaded into the picturebox, I want to resize the image so that it has a width of 500, and I want to retain the aspect ratio for the height.  So, it should be resized to 500 x ? and be fully displayed in a form (not clipped and not stretched).  How do I go about this?
Question by:adwooley2
    LVL 46

    Accepted Solution

    Hello adwooley2,

    try something like this....

            Dim img As Image = Image.FromFile("C:\YourFile.JPG")
            PictureBox1.Height = img.Height / (img.Width / 500)
            PictureBox1.Width = 500
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Image = img



    Author Comment

    Well, I adapted what you had.  Thanks for your simple solution!


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now