This is a program that enables the user to open and choose image files from the folders in his or her computer and view them in a picture box. There are two ways to implement the program. The first is to build the program from the ground up and the second makes use of the common dialog box.
The first way is a little more complicated but you can learn a great deal of programming techniques. To create this program, you need to insert a a drive list box(DriveListBox) , a directory list box (DirListBox), a file list box(FileListBox) and a combo box . The drive list box is for the user to select a drive, the directory list box is for the user to choose a folder and the file list box is display the files in the selected folder. Besides that, the combo box allows the user to select all graphics files or all files. You also need to insert a picture box to display the image.
The second way is much easier to program, you only need to insert an image control, a common dialog box and an icon that resembles on opened file. You need to set the stretchable property of the image control to true. The procedure to open the common dialog box to browse the image files as well as to load the selected picture into the image control is
The filter property of the common dialog box uses the format as shown below
to specify the file type, and uses the pipe line | to separate different file types.
Visual Basic supports most of the picture formats namely bmp, wmf, jpg, gif, ico(icon) and cur(cursor) files.
The command CommonDialog1.ShowOpen is to open the common dialog box and the command
is to load the selected picture file into the picture box.
The whole program is shown below and the output is shown in the figure below:
When the user clicks the opened file icon, the following dialog will appear. The user then can select the file he or she wish to view.
Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: email@example.com