views:

143

answers:

2

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?

+2  A: 

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.

Oren Trutner
Ah, this is what it was! This was set because ShowHelp=false made my app freeze, and at the time, I didn't specify [STAThread] for "thread-safe". Thanks!
DigiMarco
A: 

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.

MuSTaNG
While that's true, a service pack to the .NET Framework ensured that you got the new all-singing, all-dancing version of the Common File Dialog unless you deliberately set some options that made it look like you wanted old school. I'm a big Code Pack advocate but only if you need it.
Kate Gregory