openfiledialog 的 AutoupgradeEnable 属性
我需要在 winform 应用程序中显示打开文件对话框。文件对话框的一个属性,autoupgradeenabled,我将其设置为true,用于根据操作系统更新打开的文件对话框,就像应用程序在 xp 上运行一样然后对话框的显示方式与 wista 或 window 7 中不同。
因此,当我将该属性用作 true 时,并且一旦在装有 带有 2.0 .net 框架的 xp 的计算机中无法打开该打开文件对话框。所以我尝试将其设置为 false,然后也无法使用 xp 和 2.0 框架在计算机中打开它。
然后我尝试通过注释整行意味着我从代码中删除了该属性,然后我试过了,在2.0框架的xp机器上没问题。所以问题是我无法理解为什么该属性无法通过将其设置为 false 或 true 来工作。因为通过设置该属性应该适用于所有框架的所有操作系统,并且对话框应该根据操作系统进行更改。如果不是,那么该属性的含义是什么?
I had need of showing open file dialog in winform application. And one property of the file dialog, autoupgradeenabled which I set as a true, which is for updating the open file dialog according to operating system, like if application is running on xp then dialog is displayed different as in wista or window 7.
So when I used that property as a true, and once in the machine where there was xp with 2.0 .net framework that open file dialog could not be opened. So I tried by doing it false then also it could not be opened in the machine with the xp and 2.0 framework.
Then I tried by commenting that whole line means I removed that property from the code, then I tried and it was fine in xp machine with 2.0 framework. So problem is I cannot understand that why that property is not working by setting it false or true. Because by setting that property is should work in all os with all framework and dialog should be changed according to os. If not,then what is the meaning of that property ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为直到 .NET 2.0 SP1 才添加
AutoUpgradeEnabled
属性。文档 将支持的版本列出为:
在版本 2.0 SP1 之前,使用新的 Windows Vista 样式对话框自动显示
OpenFileDialog
和SaveFileDialog
。直到后来才添加了使用AutoUpgradeEnabled
属性选择退出此功能的功能。 (MSDN 参考)这并不是一个重大更改,因为根据 Brandon Turner 关于该主题的博客文章,您将获得
MissingMethodException
尝试在早期版本的框架上使用它时。因此,通过尝试设置该属性(设置为 True 或 False),您会导致程序抛出异常。正如您所描述的那样,评论并删除该行可以让一切正常工作。It didn't work because the
AutoUpgradeEnabled
property wasn't added until .NET 2.0 SP1.The documentation for that property lists the supported versions as:
Prior to version 2.0 SP1, the
OpenFileDialog
andSaveFileDialog
were automatically displayed using the new, Windows Vista-style dialogs. The ability to opt out of this with theAutoUpgradeEnabled
property wasn't added until later. (MSDN Reference) This wasn't a breaking change because the default setting for that property remained "True" when it was added to later versions.According to Brandon Turner's blog entry on the subject, you'll get a
MissingMethodException
when trying to use it on an earlier version of the Framework. Thus, by trying to set the property (to either True or False), you caused the program to throw an exception. Commenting and removing that line allowed everything to work fine, just as you described.