如何在 Vista/Win7 中自动打开新的 OpenFileDialog?

发布于 2024-09-26 17:30:02 字数 430 浏览 9 评论 0原文

我在 Vista 上并且使用 Microsoft.Win32.OpenFileDialog 类。

当我调用 ShowDialog() 时,我得到 XP 风格的对话框: alt text

如何获得新的 Vista 风格对话框并回退到 WindowsXP 上的旧版本? alt text

一点隆隆声:

我真的不明白为什么他们没有替换 vista 中的对话框,而是保留了他们俩。现在,除非更新,否则旧版应用程序永远不会打开新对话框。

I'm on Vista and I'm using Microsoft.Win32.OpenFileDialog class.

When I call ShowDialog() I get the old XP-style dialog:
alt text

How do I get the new Vista-style dialog with fallback to the old one on WindowsXP?
alt text

A bit of rumble:

I don't really understand why they didn't replace the dialog in vista, but kept both of them. Now legacy apps will never open new dialog, unless updated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一桥轻雨一伞开 2024-10-03 17:30:02

是的,您必须升级到 .NET 4.0 才能获得新对话框。如果您卡在 3.5 上,那么您可以使用 System.Windows.Forms.OpenFileDialog,它确实获得了更新以使用新的 IFileDialog COM 接口。

回退是自动的,但如有必要,您可以使用其 AutoUpgradeEnabled 属性强制保留。但事实并非如此,.NET 程序不太可能修改该对话框。

Yes, you'd have to upgrade to .NET 4.0 to get the new dialog. If you're stuck on 3.5 then you can use System.Windows.Forms.OpenFileDialog, it did get the update to use the new IFileDialog COM interface.

The fallback is automatic but you can use its AutoUpgradeEnabled property to force legacy, if necessary. Which it is not, unlikely that a .NET program would modify the dialog.

念﹏祤嫣 2024-10-03 17:30:02

您显示的第一个对话框是保存对话框而不是打开对话框。

你应该只需要这样做:

OpenFileDialog OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "My files (*.myfile)|*.myfile|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
  //openFileDialog1.FileName
}

The first dialog you showed is a save dialog not an open dialog.

You should only have to do this:

OpenFileDialog OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "My files (*.myfile)|*.myfile|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
  //openFileDialog1.FileName
}
可可 2024-10-03 17:30:02

参考 System.Windows.Forms

using System.Windows.Forms

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
    //Do Stuff
}

Reference System.Windows.Forms

using System.Windows.Forms

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
    //Do Stuff
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文