views:

100

answers:

1

I have an open modal dialog and open again a modal dialog from this dialog (with ShowDialog) The problem is now that the parent modal dialog is not locked and when I click on it the second modal dialog, it moves to the background. When I close the first modal dialog, the second one still remains on the desktop. How can I prevent this behavior or what is the problem with this scenario?

+3  A: 

Make sure you have set the dialog's Owner property. This tells WinForms/Win32 which window to disable when the new window goes modal. Do something like this:

secondDialog.Owner = firstDialog;
secondDialog.ShowDialog()

Or, try calling secondDialog.ShowDialog(firstDialog), which should set the owner chain for you.

dthorpe
+1 You should virtually always pass an owner parameter to `ShowDialog`
Tim Robinson