Use the Filtersproperty of the FileDialogobject to return a reference to the FileDialogFilters
collection for the FileDialog. The filters control the types of files that are displayed. By default, there
are 24 preset filters that the user can select from the drop-down menu at the bottom of the File➪Open
dialog box. The Clearmethod of the FileDialogFilterscollection removes the preset filters, and you
add your own filter that shows only .jpgfiles.
The Showmethod of the FileDialogobject displays the dialog box. When the user clicks the Open but-
ton, the Showmethod returns a value of True. If the user clicks the Cancel button, the Showmethod
returns Falseand you exit from the procedure.
The Showmethod does not actually open the selected file, but places the filename and path into a
FileDialogSelectedItemscollection. As you will see later, it is possible to allow multiple file selec-
tion. In the present example, the user can only select one file. The name of the file is returned from the
first item in the FileDialogSelectedItemscollection, which is referred to by the SelectedItems
property of the FileDialogobject.
Use the LoadPicturefunction to assign the file to the Pictureproperty of the Imagecontrol.
There is very little difference among the four possible dialog types, apart from the heading at the top of
the dialog. The file picker and folder picker types show Browse in the title bar, and the others show
File➪Open and File➪Save As dialogs, as appropriate. All the dialogs show directories and files except
the folder picker dialog, which shows only directories.
As you have seen, the Showmethod displays the FileDialog,and the items chosen are placed
in the FileDialogSelectedItemsobject without any attempt to open or save any files. You can
use the Executemethod with the File➪Open and File➪Save As dialogs to carry out the required
Openor Save As operations after the user clicks the Open or Save button, as shown in the
If .Show Then .Execute
Chapter 11: Text Files and File Dialog