Visual Basic Reference

LoadPicture Function

See Also    Example

Loads a graphic into a forms Picture property, a PictureBox control, or an Image control.

Syntax

LoadPicture([filename], [size], [colordepth],[x,y])

The LoadPicture function syntax has these parts:

Part Description
filename Optional. String expression specifying a filename. Can include folder and drive. If no filename is specified LoadPicture clears the Image or PictureBox control.
size Optional variant. If filename is a cursor or icon file, specifies the desired image size.
colordepth Optional variant. If filename is a cursor or icon file, specifies the desired color depth.
x Optional variant, required if y is used. If filename is a cursor or icon file, specifies the width desired. In a file containing multiple separate images, the best possible match is used if an image of that size is not available. X and y values are only used when colordepth is set to vbLPCustom. For icon files 255 is the maximum possible value.
y Optional variant, required if x is used. If filename is a cursor or icon file, specifies the height desired. In a file containing multiple separate images, the best possible match is used if an image of that size is not available. For icon files 255 is the maximum possible value.

Settings

The settings for size are:

Constant Value Description
vbLPSmall 0 System small icon.
vbLPLarge 1 System large icon size, as determined by the video driver.
vbLPSmallShell 2 Shell small icon size, as determined by the Caption Buttons size setting on the Appearance tab in the Control Panel Display Properties dialog box.
vbLPLargeShell 3 Shell large icon size, as determined by the Icon size setting on the Appearance tab in the Control Panel Display Properties dialog box.
vbLPCustom 4 Custom size, values provided by x and y arguments

The settings for colordepth are:

Constant Value Description
vbLPDefault 0 Best available match if the specified file is used.
vbLPMonochrome 1 2 colors.
vbLPVGAColor 2 16 colors.
vbLPColor 3 256 colors.

Remarks

Graphics formats recognized by Visual Basic include bitmap (.bmp) files, icon (.ico) files, cursor (.cur) files, run-length encoded (.rle) files, metafile (.wmf) files, enhanced metafiles (.emf), GIF (.gif) files, and JPEG (.jpg) files.

Graphics are cleared from forms, picture boxes, and image controls by assigning LoadPicture with no argument.

To load graphics for display in a PictureBox control, Image control, or as the background of a form, the return value of LoadPicture must be assigned to the Picture property of the object on which the picture is displayed. For example:

Set Picture = LoadPicture("PARTY.BMP")
Set Picture1.Picture = LoadPicture("PARTY.BMP")

To assign an icon to a form, set the return value of the LoadPicture function to the Icon property of the Form object:

Set Form1.Icon = LoadPicture("MYICON.ICO")

Icons can also be assigned to the DragIcon property of all controls except Timer controls and Menu controls. For example:

Set Command1.DragIcon = LoadPicture("MYICON.ICO")

Load a graphics file into the system Clipboard using LoadPicture as follows:

Clipboard.SetData LoadPicture("PARTY.BMP")