Picture assignment

As we have seen, computers can process many types of data. One of the most common these days is images (pictures).

We use PictureBoxes display images, as illustrated in this image display program. (To run this program, the following images must be on a floppy disk in drive A).

      

The listing of the program is simple:

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
   picPupProf.Image = Image.FromFile("a:magimini.jpg")
End Sub

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
   picPupProf.Image = Image.FromFile("a:einstein.jpg")
End Sub
The program assigns images to the image property of the PictureBox called picPupProf using a value returned by the FromFile method of the Image class. (How would you change the program if the image files were in a different directory)?

There are many image file formats in use. VB.NET is able to display images in the gif, jpg, and bmp formats. (The extension on the file name indicates the format). You can find many images on the Internet. To download one you like, just right click on it and save it on your disk.

There is no border around the PictureBox, and it automatically resizes, depending upon the size of the image. Can you figure out which property I set to make that happen?

Finally, there is something noteworthy about the FromFile method of the Image class. FromFile is a method of the class, not a method of a particular object of that class. FromFile and other methods that are methods of a class rather than a specific object are called shared methods.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.