Delphi OpenDialog 不允许用户导航离开初始目录
我正在尝试创建一个打开的对话框(在 Windows 7 中),其中用户被限制在初始目录中。在打开的对话框中,我已将 optionsEX 设置为 [ofExNoPlacesBar],这会删除允许他们快速选择文件夹和目录的栏,但用户可以使用面包屑地址工具向上一级并键入不同的目录进入文件名文本框以更改目录。
谢谢
I am trying to create an open dialog (in Windows 7) where the user is confined to the initial directory. On the open dialog I have set the optionsEX to [ofExNoPlacesBar] and that removes the bar that would let them select folders and directories to go to quickly but the user can use the bread crumb address tool to go up a level and type a different directory into the filename text box to change directories.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 Delphi 2009+,则有一个
TFileOpenDialog
。使用它,并设置其中
(请注意,每个
TFileOpenDialog
应该正好有一个FInitiated
。因此,如果FileOpenDialog
是的私有成员>TForm3
,让FInitiated
也成为TForm3
的私有成员。)为了改善用户体验,您可能会使用
或
If you are using Delphi 2009+, there is a
TFileOpenDialog
. Use this, and setwhere
(Notice that there should be exactly one
FInitiated
perTFileOpenDialog
. So, ifFileOpenDialog
is a private member ofTForm3
, letFInitiated
be a private member ofTForm3
as well.)To improve the user experience, you will probably use
or
使用不同的打开对话框(自己制作一个没有文件夹导航,只有文件列表框的表单),或者只是审核与初始目录不匹配的路径并拒绝实际打开文件。
Use a different open dialog (make a form yourself with no folder navigation, only a file list box), or simply audit for a path not matching the initial dir and refuse to actually open the file.
“FileOpenDialog”有一个
OnFolderChanging
类型为TFileDialogFolderChangingEvent
具有布尔CanChange
参数。我希望将此参数设置为 false 可以达到目的。编辑:
根据雷米的评论使用示例(如果我理解正确的话);
下面的方法也有效,但更容易受到路径变化的影响(请参阅下面 Andreas 的评论);
The 'FileOpenDialog' has an
OnFolderChanging
event of typeTFileDialogFolderChangingEvent
which have a booleanCanChange
parameter. I'd expect setting this parameter to false would serve the purpose.edit:
Example usage as per Remy's comments (if I understood correctly);
The below also works but more vulnerable to path variations (see Andreas' comments below);