|
|
Title | Build a custom file selection dialog |
Description | This example shows how to build a custom file selection dialog in Visual Basic 6 by using the DriveListBox, DirListBox, and FileListBox controls. |
Keywords | dialog, common dialog, file selection dialog |
Categories | Controls, Files and Directories |
|
|
The program builds its dialog on a form containing DriveListBox, DirListBox, and FileListBox controls. The controls are connected via their events. For example, when the user picks a new directory, the program sets the FileListBox control's Path property accordingly.
|
|
' True if the user canceled.
Public Canceled As Boolean
Public FileName As String
Public FilePath As String
Private Sub Form_Load()
' Assume we will cancel.
Canceled = True
FileName = ""
FilePath = ""
End Sub
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Private Sub cmdOk_Click()
' We did not cancel.
Canceled = False
FilePath = filList.Path
FileName = filList.FileName
Me.Hide
End Sub
Private Sub drvList_Change()
'On Error GoTo DriveError
dirList.Path = drvList.Drive
Exit Sub
DriveError:
drvList.Drive = dirList.Path
Exit Sub
End Sub
Private Sub dirList_Change()
filList.Path = dirList.Path
End Sub
Private Sub filList_DblClick()
cmdOk_Click
End Sub
|
|
If the user selects a new pattern from the pattern combo box, the program sets the FileListBox's Pattern property. The pattern is stored inside parentheses within the combo box's choices. For example, "Bitmap Files (*.bmp)."
|
|
Private Sub cboPattern_Click()
Dim pos1 As Integer
Dim pos2 As Integer
Dim txt As String
txt = cboPattern.Text
pos1 = InStrRev(txt, "(")
pos2 = InStrRev(txt, ")")
filList.Pattern = Mid$(txt, pos1 + 1, pos2 - pos1 - 1)
End Sub
|
|
Note that users are familiar with the standard common file selection dialog so you should only build a custom dialog when you have some special needs that the standard control cannot handle.
|
|
|
|
|
|