vb resize image so that it automatically fits

property used to resize image control in vb
visual basic image
image tool in vb6
how to load image in vb6
vb6 picturebox load image
vb6 form picture stretch
vb6 scrolling picture box
vb6 command button picture stretch

I am a newbie to VB 6 and I am facing a problem. I have a large picture. I want to place it in a quite smaller form so that it looks nice with the short text.

However when I add the picture in the picture box, the picture is added from top-left and the right and bottom parts are cut off. Sometimes I also need to re-size the picture box. So I would like to know how to make the image fit in the picture box automatically and get re-sized automatically whenever I re-size the picture box. I have searched for help but could not find any help in this context. I have also tried making the AutoSize and AutoRedraw options 'true' but still it is't working.

Can anyone please help me?

Assuming this is a VB6 question and not VB.NET as you've tagged it...

If you just want to display a picture and don't require any of the other properties, methods and events associated with a PictureBox, you can use an Image control and set its Stretch property to True.

If you do need it to be a PictureBox, you can do it by adding a second, hidden, AutoSizing PictureBox which is set to the desired picture then use code like this to draw it rescaled onto the visible PictureBox.

pbxShown.PaintPicture pbxHidden.Picture, _
        0, 0, pbxShown.ScaleWidth, pbxShown.ScaleHeight, _
        0, 0, pbxHidden.ScaleWidth, pbxHidden.ScaleHeight, _

Resize image to fit in picturebox, set image in BackgroundImage property of picture-box then set picture-box's BackgroundImageLayout = stretch thus Image will auto fit to size of  Public Shared Function ResizeImage(ByVal InputImage As Image) As Image Return New Bitmap(InputImage, New Size(64, 64)) End Function. "InputImage" is the image you want to resize. "64 X 64" is the required size you may change it as your needs i.e 32X32 etc. improve this answer. answered Mar 18 '14 at 8:39. 27 silver badges. 40 bronze badges.

Set AutoSize Property to True of Picture Box Property

PictureBox.SizeMode Property (System.Windows.Forms), Indicates how the image is displayed. Using the StretchImage value causes the image to stretch or shrink to fit the PictureBox. Using the Zoom value causes  Currently there is no way to do this correctly in a deterministic way, with fixed-size images such as JPEGs or PNG files. To resize an image proportionally, you have to set either the height or width to "100%", but not both. If you set both to "100%", your image will be stretched.

Code to automatically stretch loaded picture in picture box,

Private Sub AutoSizeToPicture(Picture1 As PictureBox)
    Picture1.ScaleMode = 3
    Picture1.AutoRedraw = True
    Picture1.PaintPicture Picture1.Picture, _
    0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _
    0, 0, Picture1.Picture.Width / 26.46, _
    Picture1.Picture.Height / 26.46
End Sub

[RESOLVED] picturebox: resize image to fit-VBForums, GIF file be automatically resized to fit a picturebox on loading? Picture is not a control, it's an Object and it's native to VB6 so you don't need  Basically it creates a new blank graphic to the dimensions you request, then copies the original image to it while scaling it to fit. I think if you step throw it a line at a time you should be pretty self explanatory, but ask if you have questions

Pro Silverlight 3 in VB, This automatic sizing is one-way only, so columns don't shrink when you leave large Initially, the Description column is made extremely wide to fit this data,  You can do it with following steps: Step 1: Insert the pictures in to a worksheet, and select a picture that you will resize it Step 2: Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Step 3: Click Insert > Module , and paste the following macro in the

Pro Silverlight 4 in VB, This automatic sizing is one-way only, so columns don't shrink when you leave large Initially, the Description column is made extremely wide to fit this data,  I've a datagridview of height and width 300x300 size. I'm reading image from memory stream. I want to resize image into datagridview column such that it fit in it. I've following code this is code

Auto adjust windows form size according to screen resolution in vb net, C# windows form for all screen size With resize Re: vba to automatically resize Is there a way to prepare the image to be displayed so it will fit correctly in the  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more vb resize image so that it automatically fits

  • @ArghyaChakraborty: Eh? It's a standard component in the VB6 toolbox. You add it the same way you add any other control...
  • Hey I understood it. Its fantastic ... +1 for you