OpenFileDialog.AutoUpgradeEnabled doesn't work under Vista or 7?

拜拜、爱过 提交于 2019-12-13 06:44:01

问题


If I specify OpenFileDialog.AutoUpgradeEnabled = true, my program still shows the old XP-style dialog. Any idea why this would happen? This is after I enable theming in Main()

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new Primary());
}

and this is my dialog code:

private void OpenProgramFile()
{
    OpenFileDialog programFileDialog = new OpenFileDialog();
    programFileDialog.Filter = "Program files (*.exe;*.lnk)|*.exe|All files (*.*)|*.*";
    programFileDialog.FilterIndex = 0;
    programFileDialog.Title = "Select program file";
    programFileDialog.AutoUpgradeEnabled = true;
    programFileDialog.ShowHelp = true;

    DialogResult fileResult = programFileDialog.ShowDialog();
    if (fileResult != DialogResult.OK)
        return false;

    programFileDialog.Dispose();
}

So why would AutoUpgradeEnabled not work?


回答1:


Avoid setting programFileDialog.ShowHelp=true. The ShowHelp property is not compatible with the Vista/7 file dialog UI. The open file dialog will still show a question-mark help icon.




回答2:


If you want to have Windows Vista or Windows 7 style dialogs you should use the Microsoft Windows API Code Pack: http://code.msdn.microsoft.com/WindowsAPICodePack. This includes all the Windows 7 Style dialogs.



来源:https://stackoverflow.com/questions/2941240/openfiledialog-autoupgradeenabled-doesnt-work-under-vista-or-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!