7.4 Drive, Directory and File List boxes With just a few lines of code, you can add functionality to your programs by allowing users to select files when needed in a program. This example application when completed, will let the user see three different types of Windows images on the screen. The program uses five controls: a drive list box, a directory list box, a file list box, an image control, and a label. Activity 7.4 Picture Viewer Steps: 1) Choose New Project from the File menu. 2) Create 5 controls: a drive list box, a directory list box, a file list box, an image control, and a label. 3) In the properties window, set properties for the objects according to the following table: Object Property Setting Form Caption Picture Viewer Drive list box Name drvList Directory list box Name dirList File list box Pattern *.BMP; *.WMF; *.ICO Name filList BorderStyle 1 - fixed single Name imgOpen Stretch True BorderStyle 1 - fixed single Caption (Empty) Name lblPathName Image Control Label Your screen should resemble: 4) To make the drive, directory and file list boxes work in conjunction with each other, you need to add the following code to the drvList_Change and dirList_Change event procedures: Private Sub drvList_Change () dirList.Path = drvList.Drive ' Update directory path if drive changes End Sub Private Sub dirList_Change () filList.Path = dirList.Path ' Update file path if directory changes End Sub 5) When a user double clicks on a file listed in the file list box, we want the filList_DblClick event procedure to display the full path name of the selected file in the label control and display the picture itself in the image control. This is how this is done: Private Sub filList_DblClick () If Right (filList.Path, 1) <> "\" Then ' If current path doesn't end in a \ lblPathName.Caption = filList.Path & "\" & filList.FileName ' add it Else ' If it already has a \ lblPathName.Caption = filList.Path & filList.FileName ' add name End If imgOpen.Picture = LoadPicture(lblPathName.Caption) ' load picture End Sub