I have this code:
public partial class Form1 : Form
{
public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e)
{
FolderSelect("Please select:");
}
public static string FolderSelect(string txtPrompt)
{
// Now, we want to use the path information to population
// our folder selection initial location
string initialCheckoutPathDir = ("C:\\");
System.IO.DirectoryInfo info =
new System.IO.DirectoryInfo(initialCheckoutPathDir);
FolderBrowserDialog FolderSelect = new FolderBrowserDialog();
FolderSelect.SelectedPath = info.FullName;
FolderSelect.Description = txtPrompt;
FolderSelect.ShowNewFolderButton = true;
if (FolderSelect.ShowDialog() == DialogResult.OK)
{
string retPath = FolderSelect.SelectedPath;
if (retPath == null)
retPath = "";
DriveRecursion(retPath);
}
else
return "";
}
}
So i have a WindowsForm with a button. The user presses the button, and the FolderBrowserDialog appears. Once the user selects a drive, i want the form (with the button) to close as well.
I haven’t been having any luck. Any ideas? Syntax would greatly be appreciated.
After the
FolderSelectreturnsDialogResult.OK, you need to callthis.close. So like this:Edit:
For some reason your
FolderSelectmethod is static. You should remove the static so it has a reference to the form.