LoadPicture Function

See Also6J009Z1              ExampleMH1S5I>Low

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")


See Also

DragIcon Property3G3M07O

Icon Property2S1DMPP

Picture Property4GBE5Q

SavePicture Statement2U07NJP

SetData Method3EBYPZ


LoadPicture Function Example

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