How to fit images when using picture box

Asked By 0 points N/A Posted on -
qa-featured

I am using Visual Basic 6 in creating programs for my subject.

This is a simple file maintenance program. 

I am having a problem of putting a background picture on forms.

I am using a picture box, whenever I place a picture inside the Picture Box it displays the original size of the image.

I want this image to fit inside the Picture Box. 

Can someone help me with this?

 

 

SHARE
Answered By 0 points N/A #126148

How to fit images when using picture box

qa-featured

One way to solve this problem is to set the size of an image based on the size of the picture box. But if your picture box is in full screen mode, you have to set also the image size on to full screen mode.

But when compiling the programs and making it an installer it may cause stack over flow with the program if you have too many large pictures in your program.

The best solution is to scale the image based on the size of the picture box. It is also best that we only load the picture on the form when it is really needed.

Set a path for the image that you want to load. Follow the example below: you should put this inside Form_Paint or PictureBox_Paint to make this works. The auto redraw properties of the picture box must be set to true.

Img = App.path & “[Folder name]image.jpg”

PictureBox.Picture = LoadPicture(Img)

PictureBox.PaintPicture PictureBox.Picture, 0, 0, PictureBox.ScaleWidth, PictureBox.ScaleHeight

Whenever you load the form, it will call for the location of the image and displays it. It will automatically resize the image according to the size of the form.

Related Questions