Dir1-目錄列表控件
Drive1-驅動器列表控件
File1-文件列表控件
Image1-圖像控件
Text1-文本框控件
Option1-單選控件(Caption為"通過單擊瀏覽")
Option2-單選控件(Caption為"通過雙擊瀏覽")
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo DriErr
Dir1.Path = Drive1.Drive
Exit Sub
DriErr:
If Err.Number = 68 Then
If MsgBox("請問要重試還是取消?", vbRetryCancel + vbCritical, "硬盤不存在或光驅沒有插入磁盤!") = vbRetry Then
Resume 0
Else
Drive1.Drive = "C:"
Resume Next
End If
End If
End Sub
Private Sub File1_Click()
If Option2.Value = True Then Exit Sub
Dim picFile As String
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName
End If
Image1.Picture = LoadPicture(picFile)
Text1.Text = picFile
End Sub
Private Sub File1_DblClick()
If Option1.Value = True Then Exit Sub
Dim picFile As String
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName
End If
Image1.Picture = LoadPicture(picFile)
Text1.Text = picFile
End Sub