示例
Sub DisplayOpenFileDialog() Dim openFile As New System.Windows.Forms.OpenFileDialog() openFile.DefaultExt = "doc" openFile.Filter = "Word documents (*.doc)|*.doc" openFile.ShowDialog() If openFile.FileNames.Length > 0 Then Dim filename As String For Each filename In openFile.FileNames ' Insert code here to process the files. Next End If End Sub
编译代码
如果将此代码放置于 Windows 窗体的某一方法中,并且如果还在名为 openFile 的窗体上具有 OpenFileDialog 控件,则可能会产生意外的结果。此方法创建名为 openFile 的 OpenFileDialog 的新实例。
Filter 属性要求搜索字符串位于管道符号 ( |
) 后。