So I have my main form which will open another form from a menu option:
mstages = new MaterialStages( ofd.FileName );
mstages.ShowDialog();
Then in this form it checks to see if a file path is valid, if it isn’t and the user can’t provide one, I want the form to close.
DirectoryInfo di = null;
if ( findDataFolder() )
di = new DirectoryInfo( Program.dataPath );
else Close();
//rest of the function
I’ve looked and the findDataFolder() is functioning correctly returning true and false when it needs to and the else is getting executed on ‘false’ returns. But it doesn’t close the form and continues on with the rest of the function causing errors because the DirectoryInfo doesn’t have valid data.
How can I return to the main form and close this one?
Close does not stop the processing.
Use Return after Close();
Although you might want to consider restructuring your code a little:
or
Ideally, you really want to return the results of the Dialog: