📄 在commondialog控件中如何选取多个文件.txt
字号:
CommonDialog控 件 的 Flags属 性 有 一 个 标 志 cdlOFNAllowMultiselect。 利 用 这 个 标 志 可 以 实 现 多 选 。 如 :
CommonDialog1.Flags = CommonDialog1.Flags + cdlOFNAllowMultiselect
无 论 是 在 Windows NT 4.0 还 是 在 Windows 95 中 , 如 果 cdlOFNAllowMultiselect 标 志 被 单 独 使 用 , 都 不 能 支 持 长 文 件 名 。 这 是 因 为 多 重 文 件 名 要 包 括 空 格 分 隔 符 , 而 长 文 件 名 也 可 能 包 括 空 格 符 。 在 Windows NT 3.5 中 , 无 法 避 免 这 种 情 况 。 如 果 使 用 cdlOFNAllowMultiselect, 就 不 能 看 到 长 文 件 名 。 如 果 在 Windows 95 中 添 加 cdlOFNExplorer 标 志 , 就 可 以 既 能 文 件 多 选 , 又 能 看 到 长 文 件 名 。 但 是 , 这 些 文 件 名 是 用 空 字 符 Chr(0)分 隔 符 , 而 不 是 空 格 分 隔 符 隔 开 。 因 此 , cdlOFNAllowMultiselect 和 cdlOFNExplorer 一 起 使 用 时 , 在 Windows 95 和 Windows NT 3.5中 需 要 不 同 的 文 件 名 所 得 结 果 的 语 法 分 析 。
当 使 用 cdlOFNAllowMultiselect 标 志 时 , 可 能 希 望 增 加 MaxFileSize 属 性 的 尺 寸 以 便 对 所 选 文 件 名 有 足 够 的 内 存 。 MaxFileSize 属 性 要 分 配 内 存 以 便 存 储 所 选 的 一 个 或 多 个 文 件 的 实 际 名 称 。 该 属 性 的 范 围 是 1-32K。 缺 省 值 是 256。
下 面 是 一 个 例 子 :
Private Sub Command1_Click()
Dim I As Integer
Dim Y As Integer
Dim Z As Integer
Dim FileNames$()
CommonDialog1.FileName = ""
CommonDialog1.Filter = "All Files|*.*"
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.Action = 1
CommonDialog1.FileName = CommonDialog1.FileName & Chr(0)
Z = 1
For I = 1 To Len(CommonDialog1.FileName)
I = InStr(Z, CommonDialog1.FileName, Chr(0))
If I = 0 Then Exit For
ReDim Preserve FileNames(Y)
FileNames(Y) = Mid(CommonDialog1.FileName, Z, I - Z)
Z = I + 1
Y = Y + 1
Next
If Y = 1 Then
Text1.Text = FileNames(0)
Else
Text2.Text = ""
For I = 0 To Y - 1
If I = 0 Then
Text1.Text = FileNames(I)
Else
Text2.Text = Text2.Text & UCase(FileNames(I)) & _
Chr$(13) & Chr$(10)
End If
Next
End If
End Sub
<END>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -