Picture Property Example

This example loads icons from the Visual Basic icon library into two of three PictureBox controls. When you click the form, the third PictureBox is used to switch the icons. You can use any two icons. Paste the code into the Declarations section of a form that has three small PictureBox controls (for Picture3, set Visible = False). Press F5 to run the program, and then click the form.

Private Sub Form_Load ()
   ' Load the icons.
   Picture1.Picture = LoadPicture("ICONS\COMPUTER\TRASH02A.ICO")
   Picture2.Picture = LoadPicture("ICONS\COMPUTER\TRASH02B.ICO")
End Sub

Private Sub Form_Click ()
   ' Switch the icons.
   Picture3.Picture = Picture1.Picture
   Picture1.Picture = Picture2.Picture
   Picture2.Picture = Picture3.Picture
   ' Clear the third picture (not necessary if not visible).
   Picture3.Picture = LoadPicture()
End Sub

This example pastes a bitmap from the Clipboard into a PictureBox control. To find the value of Clipboard format constants (starting with vbCF), see the Visual Basic (VB) object library in the Object Browser. To try this example, paste the code into the Declarations section of a form that has a PictureBox control. Press F5, and then in another application, copy an icon onto the Clipboard, switch to Visual Basic, and click the form.

Private Sub Form_Click ()
   Picture1.Picture = Clipboard.GetData(vbCFDIB)
End Sub