Search Tools Links Login

VB6 Tutorial 25: PictureBox and Image Controls


Today I'll show you the usage of PictureBox and Image controls.

There are some differences between the two controls. There are certain cases when the Image control is suitable, and in some other, the PictureBox control will make your task easier, though both of them share the same job. So lets dig into some details!

Where to use images?

The first plain fact to know is that the Image and PictureBox controls are used to display pictures or icons on the form. You develop a software and you don't use any picture, that does not make sense. You generally use pictures or icons for the company logo and to make your software more graphical that'll surely make your application user-friendly. You can make use of the images on the splash screen and in many other cases.

Supported Picture Formats

The supported picture formats for these control include BMP, DIB (bitmap), ICO (icon), CUR (cursor), WMF (metafile), EMF (enhanced metafile), GIF and JPEG. You can't use a PNG format.

First off, I'll talk about the PictureBox control and then the Image control. Lastly the comparison and differentiation between them will be discussed along with the explanation of when to use one or another.

The PictureBox control

The following points describe a PictureBox control:

Example

Picture1.Picture = LoadPicture("D:\\PictureName.jpg")

Example

Image1.Picture = LoadPicture("D:\\PictureName.jpg")

Clearing the current image: You can clear the current image of the PictureBox or Image control in design time by clearing the value of Picture property. This can also be done in run-time in the following way.

Picture1.Picture=LoadPicture("")

or

set Picture1.picture=Nothing

The attached project shows how to load a picture control, given a full path and filename of the picture to load. Don't worry; we'll get in to a much better example when we talk about drive, directory, and file selection controls, later in the lessons.

The Image Control

The image control has almost the same features of PictureBox. Loading Images: You load an image in the same way.

Example

Image1.Picture = LoadPicture("D:\\PictureName.jpg")

The image control also has a Stretch property. If you set the Stretch property to true, it stretches the picture to fit in the control.

How the Image control is different from PictureBox?

Copying an image from one control to another

You can assign the Picture property of one control to another.

Example

Picture2.Picture = Picture1.Picture

Or,

Image2.Picture = Image1.Picture

As a conclusion I want to say that many Visual Basic programmers prefer the Image control over PictureBox as the Image control consumes less memory resource resulting a faster loading of it. Besides, it supports all the events a pictureBox can have, and you can even have a border around it from the BorderStyle property.

The only big limitation is that it cannot work as a container. For this reason, the PictureBox control can be sometimes preferred much. But above all, you should always choose one which is appropriate for your application.

About this post

Posted: 2018-04-07
By: vb6boy
Viewed: 10,846 times

Categories

Visual Basic 6

VB6 Tutorial

Attachments

ImageShow.zip
Posted: 4/7/2018 6:57:30 AM
Size: 1,067 bytes


Loading Comments ...

Comments

AnonymousCoward posted this comment on 2020-05-13:

Thanks

AnonymousCoward posted this comment on 2020-07-05:

Thanks Great help

AnonymousCoward posted this comment on 2021-01-02:

Any way to freely rotate an image or picturebox with dragging the mouse? Like a circular slide rule?

I can do left and right, but can't figure out how to spin.

alchle@hotmail.com

Thanks

AnonymousCoward posted this comment on 2022-06-11:

Thanks a lot for your contribution

You must be logged in to make a comment.

ADODB.Connection error '800a0e79'

Operation is not allowed when the object is open.

/assets/inc/inc_footer.asp, line 37