本机文件打开/保存对话框(没有 Windows 窗体或 WPF)
如何导入和使用本机打开文件对话框? 在不使用 Windows 窗体或 WPF 的应用程序中,它有什么好处吗?还是只是参考一下?
How to import and use native Open file dialog?
Does I have any benefits of it in application that not use Windows Forms nor WPF? Or just reference it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
WinForms 和 WPF 提供的标准文件对话框仅仅是本机对话框的包装器。因此,使用这些托管 C# 类最有意义。
如果您希望以任何方式自定义对话框(例如向对话框添加控件),那么可能需要使用本机 API。但这主要是因为您需要对 XP 使用与 Vista/7 不同的自定义技术。即使在纯本机代码中,自定义文件对话框也很重要,如果可以的话,您确实应该避免这样做。
The standard file dialogs offered by WinForms and WPF are merely wrappers around the native dialogs. So it makes most sense to use these managed C# classes.
If you wish to customise the dialogs in any way (e.g. adding controls to the dialog) then there may be a case for using the native API. But that's mainly because you need to use a different customisation technique for XP from that used for Vista/7. Even in pure native code, customising file dialogs is non-trivial and you should really avoid doing it if you reasonably can.
Windows API 代码包 中有常用对话框的包装器。在 Vista 之前发布的某些版本的 Windows 窗体和 WPF 在构建对话框时使用了一些参数,导致 Vista(或 Windows 7)说“哦,你知道你想要什么,我不会给你所有的一切 -跳舞新版本的对话。”从那时起,就有了服务包、新版本等来解决这个问题。如果由于某种原因无法获得正确的对话框,请首先为您使用的任何版本的 Visual Studio 安装任何服务包。如果您仍然不满意,请尝试代码包。
There are wrappers for the common dialogs in the Windows API Code Pack. Some versions of Windows Forms and WPF, released before Vista, used some parameters when constructing the dialogs that caused Vista (or Windows 7) to say "oh, you know what you want, I won't give you the all-singing all-dancing new versions of the dialogs." Since then there have been service packs, new releases etc that took care of that. If for some reason you can't get the right dialogs, start by installing any service packs for whatever version of Visual Studio you're using. If you still get no satisfaction, try the Code Pack.
这取决于您对应用程序的处理方式。如果是使用 Windows 窗体编写的,请使用 System.Windows.Forms.OpenFileDialog;如果是使用WPF编写的请参见这里:
WPF 的 OpenDialog
如果由于某些特殊原因您必须违背 Win32 api,请继续阅读此处的 GetOpenFileName:
http://msdn.microsoft.com/ en-us/library/ms646927%28v=vs.85%29.aspx
This is a matter of what you're doing with your application. If it's written using Windows Forms, use System.Windows.Forms.OpenFileDialog; if it's written using WPF see here:
OpenDialog for WPF
if for some peculiar reason you must go against the Win32 api, go ahead and read up on GetOpenFileName here:
http://msdn.microsoft.com/en-us/library/ms646927%28v=vs.85%29.aspx