See Also Example 1 Example 2
Form, image, OLE control , picture box .
Determines a graphic to be displayed in a control. For OLE control: not available at design time and read-only at run time.
[form.][image. | ole. | picturebox.]Picture[ = picture ]
The Picture property settings are:
(none) (Default) No picture.
(Bitmap, icon, metafile) Specifies a graphic. You can load the graphic from the Properties window at design time. At run time, you can also set this property using the LoadPicture function on a bitmap , icon , or metafile .
At design time, you can transfer a graphic with the Clipboard At run time, you can use Clipboard methods such as GetData , SetData , and GetFormat with the non-text Clipboard formats CF_BITMAP, CF_METAFILE, and CF_DIB, as defined in CONSTANT.TXT, a Visual Basic file that specifies system defaults. using the Copy, Cut, and Paste commands on the Edit menu.
When setting the Picture property at design time, the graphic is saved and loaded with the form. If you create an executable file, the file contains the image. When you load a graphic at run time, the graphic is not saved with the application. Use the SavePicture statement to save a graphic from a form or picture box into a file.
Note At run time, the Picture property can be set to any other object's DragIcon , Icon , Image , or Picture property, or you can assign it the graphic returned by the LoadPicture function.
Chapter 15, "Creating Graphics for Applications"
Picture Property Example 1
The example loads icons from the Visual Basic Icon Library When you click the form, the third picture box is used to switch the bitmaps. You can use any two icons. Paste the code into the Declarations section of a form that has three small picture boxes (for into two of three picture boxes.Picture3, set Visible = False). Press F5 to run the program and then click the form.
Sub Form_Load ()
' Load the bitmaps.
Picture1.Picture = LoadPicture("icons\computer\trash02a.ico")
Picture2.Picture = LoadPicture("icons\computer\trash02b.ico")
Sub Form_Click ()
' Swap the bitmaps.
Picture3.Picture = Picture1.Picture
Picture1.Picture = Picture2.Picture
Picture2.Picture = Picture3.Picture
' Set the picture to none (not necessary if not visible).
Picture3.Picture = LoadPicture()
Picture Property Example 2
The example pastes a bitmap from the Clipboard into a picture box. To find the value of the CF_formats, look at the CONSTANT.TXT file or load it into a module. To try this example, paste the code into the Declarations section of a form that has a picture box. Press F5 and then in another application, copy a picture onto the Clipboard, switch to Visual Basic, and click the form.
Sub Form_Click ()
Const CF_BITMAP = 2
Picture1.Picture = Clipboard.GetData(CF_BITMAP)