View contents of this chapter

Image Control: Example

In this section, you will develop a small program that shows a graphic file. Start a new project and place two command buttons and an image control on the form. Your application should look like the one shown in the following figure:

The source code needed for this example is stored in the
"Source Code\Chapter11\PicViewer" directory available in the CD. To open the project double click the "PicViewer.vbp" file.

Private Sub cmdClear_Click()
  imgViewer.Picture = LoadPicture()
End Sub

Private Sub cmdShow_Click()
  imgViewer.Picture = LoadPicture(App.Path & "\ut.jpg")
End Sub

The command button cmdShow is used to show an image. The App object is a global object accessed with the App keyword. It determines or specifies information about the application's title, version information, the path and name of its executable file and Help files, and whether or not a previous instance of the application is running.

The second button cmdClear is used to clear the Image.

© Universal Teacher Publications        INDEX Previous Screen Next Screen