All that you did in your code was start to declare a variable.
Here's what you need to do
Code: Select all
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() != DialogResult.Cancel)
{
// do whatever you want on a successfull dialog(user didn't press X or cancel)
}
I'll split up something most programmers do in one step into two steps to hopefully give you an idea of what's going on.
When you say
it just creates a variable with nothing in it(null)
when you say
it creates a new object of FolderBrowserDialog and puts the pointer to where it is in memory into your fbd variable.
This was done in one step in the example I gave.
when you run the ShowDialog method, it returns a DialogResult
The way I gave is the way I usually do it, but you can store the result in a variable if you want
Code: Select all
DialogResult dr = fbd.ShowDialog();
Then you could perform more than one if statement on it, or use a switch.