I’m attempting to create a custom dialog (using WinForms) that, much like a ColorDialog or OpenFileDialog, opens and accepts some input from the user, then returns execution to the parent form once input has been recieved.
I attempted to accomplish this by just creating a custom form that had a Show() method, then calling it like this:
custom_dialog.Show();
var results = custom_dialog.Property;
As you could imagine, this did not work as the second line was executed before any input was selected.
My question is: How can I create a custom dialog that will hang the execution of the parent form, as a ColorDialog or OpenFileDialog does, so that I can force the user to input something before execution continues?
you should call
ShowDialog(), this will open the dialog as modal and you will continue execution in the calling form only after dialog has been closed.It is a good practice to use the
usingblock around the modal form so it gets disposed immediately once running out of such block.