In Visual Studio 2008 there is a folder browser dialog that looks like this (very similar to file open dialog):
Does anyone know how to invoke it from code?
In Visual Studio 2008 there is a folder browser dialog that looks like this (very similar to file open dialog):
Does anyone know how to invoke it from code?
At the end I just used the VistaBridge library to open it.
If you're using C#, this solution is for you. Source code provided here: http://www.lyquidity.com/devblog/?p=136 (.NET Win 7-style folder select dialog). [Update: if site is dead, here's a wayback machine link.]
How does it work? It turns out that the ability to show a Vista-like dialog is present in .NET but the methods are not public. So the ShowDialog() method uses reflection to call CreateVistaDialog and pass in all the parameters. The technique to do this is taken from the Google code project FED.
You don't need to use a whole library like VistaBridge, or a Windows API code pack, to get a nice Folder Dialogue, just two small source files. Gives you a nice folder dialogue like this:
At the end I just used the VistaBridge library to open it.
Is this the pinvoke of SHBrowseForFolder, with the BIF_NEWDIALOGSTYLE style? If so there is an example on that page.
Drag a FolderBrowserDialog component from the Dialogs tab of the Toolbox to the form. Add this code to you button handler.
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.label1.Text = folderBrowserDialog1.SelectedPath;
}
© 2022 - 2024 — McMap. All rights reserved.