In C#, I would like to create a function (method) that has the following behavior:
- When called, create and show a form.
- Wait for the user to enter or select a value on the form.
- Return the selected value.
Is there a concise, readable way to implement this function?
If you are looking for dialog functionality, WPF and WinForms both support this. You simply invoke
ShowDialog()on the window / form being shown. This is a blocking call, so until you close the shown dialog, you won’t return processing to the calling window.To return values from this call, simply make properties on your Form / Window, and then inspect those after ShowDialog().