-1

I am trying to make a folder selection which would show an error if there isn't enough space on the selected drive. I have created a custom designed error and dialog form, but there is a problem with using the FolderBrowserDialog.

Here is my actual code:

frmDialog dialog = new frmDialog("Install software", "The software cannot be found. Please select the path of the executable or let the launcher install it for you.");
dialog.SetYesButtonText("Install software");
dialog.SetNoButtonText("Browse for executable...");

if (dialog.ShowDialog() == DialogResult.Yes)
{
     fbd = new FolderBrowserDialog();
     fbd.Description = "Please select where do you want to install the software!";
     DialogResult result = fbd.ShowDialog();

     if (result == DialogResult.OK) // + space checking, but I deleted it for debugging now.
     {
          frmError error = new frmError("Not enough space", "Please select a folder with at lease 22 MB of free space.");
          error.ShowDialog();
      }
}

I will actually make a loop afterwards which will run until the user selects a folder with enough space or cancels the selection.

The problem is that the error dialog does not get any focus. So when the user selects the folder, the FolderBrowserDialog disappears, and the error dialog shows up in a new window, but the Visual Studio's window gets the focus instead of the error dialog. As I experienced, this issue is not existing with my own forms, so if I changed the fdb to frmDialog, all the three dialogs would appear with focus after each other.

rene
  • 41,474
  • 78
  • 114
  • 152
TMS
  • 43
  • 1
  • 12

1 Answers1

3

Set the owner of the dialogs like this:

fbd.ShowDialog( dialog );
error.ShowDialog( dialog );

I recommend to set the owners of the other dialogs to set a parent child relationship. So when you close the parent form, the child forms closes to. And also put a using block around your forms if you're using the ShowDialog calls.

Sievajet
  • 3,443
  • 2
  • 18
  • 22