How to Change a PictureBox Image in VB Code

Written by sean mann
  • Share
  • Tweet
  • Share
  • Email

Adding a PictureBox lets you display an image in your Visual Basic, or VB, program. User interaction with the program's interface may require an image change, such as when selecting a different object from a menu or clicking a button that loads new content. You can use the "FromFile" method to change which image the PictureBox is displaying.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Open your VB source file in an editor, such as Microsoft Visual Studio Express.

  2. 2

    Add a function to handle an event that will activate the PictureBox image change. For example, using a button named "Button2", add the code "Private Sub Button2_Click(ByVal sender as System.Object, ByVal As System.EventArgs) Handles Button2.Click."

  3. 3

    Change the PictureBox image by adding the code "MyPictureBox.Image = Image.FromFile("myimage.jpg")." Replace "myimage.jpg" with the image path of your file. The "FromFile" method will load your image into the PictureBox.

  4. 4

    Close the function by adding the code "End Sub."

  5. 5

    Save the VB file, compile and run it to see your PictureBox image change.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.