.NET Winform Custom Form - Needs to return DialogResult or somehow prevent asynchronous events

StackOverflow https://stackoverflow.com/questions/3693337

  •  02-10-2019
  •  | 
  •  

Question

I have a form that calls a custom child form. The child form is basically a popup box that gets some user data.

I want the Parent form to process information returned by the Child form.

The problem is, the Parent form is calling the Child, and isn't waiting for a reply.

Ideally, I'd like to make the Child form return a DialogResult. Functionally, this is clear what's happening (especially since the user has the option to Cancel the child control) and seems like a simple way to force the parent to wait. I haven't figured out how to do this though.

The secondary problem is, the Parent control proceeds beyond the childDialog.Show() event, and tries to process the Child control's info. Which hasn't been altered yet.
Setting up a condition using public values of the Child control, such as childDialog.UserClickedOK, don't do a thing to help, since the default values are still in effect.

What am I overlooking?

Thanks everyone! :)

Was it helpful?

Solution

You need to show the form modally, using ShowDialog instead of Show. Inside your child form, you set the DialogResult to whatever makes the most sense given the user interaction that happened before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top