See Also Example
Loads a picture into a form, picture box, or image control.
Syntax
LoadPicture([stringexpression])
Remarks
The argument stringexpression is the name of a picture file to be loaded. Pictures are cleared from forms, picture boxes, and image controls by assigning LoadPicture with no argument.
Picture files recognized by Visual Basic include bitmaps (.BMP), icons (.ICO), run-length encoded files (.RLE), and metafile (.WMF) files.
To load pictures for display in a picture box, 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:
Picture = LoadPicture("PARTY.BMP")
Picture1.Picture = LoadPicture("PARTY.BMP")
To load icon files (.ICO) to the form icon, the return value of LoadPicture must be assigned to the Icon property of form:
Icon = LoadPicture("MYICON.ICO")
Icons can also be assigned to the DragIcon property of all controls except timers and menus. For example:
Command1.DragIcon = LoadPicture("MYICON.ICO")
Load a picture file into the operating environment Clipboard using LoadPicture as follows:
Clipboard.SetData LoadPicture("PARTY.BMP")
DragIcon Property
Icon Property
Picture Property
SavePicture Statement
SetData Method
The example uses the LoadPicture function to load a picture into a form and to clear the picture from the form. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Msg ' Declare variables.
On Error Resume Next ' Set up error handling.
Height = 3990: Width = 4890 ' Set height and width.
Picture = LoadPicture("PAPER.BMP") ' Load bitmap.
If Err Then
Msg = "Could not find the .BMP file."
MsgBox Msg ' Display error message.
Exit Sub ' Quit if error occurs.
End If
Msg = "Choose OK to clear the bitmap from the form."
Msgbox Msg
Picture = LoadPicture() ' Clear form.
End Sub