Dim picpath As String'用到的控件drive1 dir1 file1 image1 picture1 Private Sub Command1_Click() Picture1.Picture = LoadPicture(picpath) End SubPrivate Sub Command2_Click() End End SubPrivate Sub Dir1_Change() File1.Path = Dir1.Path End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1.Drive End SubPrivate Sub File1_Click() '单击预览 If Right$(Dir1.Path, 1) <> "\" Then picpath = Dir1.Path & "\" & File1.FileName Else picpath = Dir1.Path & File1.FileName End If Image1.Picture = LoadPicture(picpath) End SubPrivate Sub File1_DblClick() '双击打开 Picture1.Picture = LoadPicture(picpath) End SubPrivate Sub Form_Load() Image1.Stretch = True File1.Pattern = "*.jpg;*.bmp" End Sub
Path 属性示例 该例子为选中的驱动器和目录显示一文件列表。要试用此例,先将以下代码粘贴到包含 DriveListBox、DirListBox、和 FileListBox 控件的窗体的声明部分。然后按下 F5 键。使用鼠标来改变驱动器或目录。Private Sub Drive1_Change () Dir1.Path = Drive1.Drive '设置目录路径。 End SubPrivate Sub Dir1_Change () File1.Path = Dir1.Path '设置文件路径。 End Sub
Private Sub Command1_Click()
Picture1.Picture = LoadPicture(picpath)
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub File1_Click() '单击预览
If Right$(Dir1.Path, 1) <> "\" Then
picpath = Dir1.Path & "\" & File1.FileName
Else
picpath = Dir1.Path & File1.FileName
End If
Image1.Picture = LoadPicture(picpath)
End SubPrivate Sub File1_DblClick() '双击打开
Picture1.Picture = LoadPicture(picpath)
End SubPrivate Sub Form_Load()
Image1.Stretch = True
File1.Pattern = "*.jpg;*.bmp"
End Sub
该例子为选中的驱动器和目录显示一文件列表。要试用此例,先将以下代码粘贴到包含 DriveListBox、DirListBox、和 FileListBox 控件的窗体的声明部分。然后按下 F5 键。使用鼠标来改变驱动器或目录。Private Sub Drive1_Change ()
Dir1.Path = Drive1.Drive '设置目录路径。
End SubPrivate Sub Dir1_Change ()
File1.Path = Dir1.Path '设置文件路径。
End Sub