Waiting for an event

  • Thread starter Thread starter Jon Cosby
  • Start date Start date
J

Jon Cosby

I have a form that needs to take input from another form. Problem is I can't
see any way to pause the sequence in the main form to wait for input from
the second form.


prompt = new AddressPrompt();
prompt.Show();
// Wait for click event in prompt
if (prompt.okay)
address[index] = prompt.addressInput;


Is there any way to do this? I've thought about creating a public method in
the main form, but I don't think there's a way to reference the open window.


Jon Cosby
 
So, you are basically trying to show a dialog, then use information that the
user input into the dialog to continue your processing?

If that's correct, it sounds as though you want to show the AddressPrompt()
form modally.
Do a couple of things:

On "Ok" button on the AddressPrompt form, set its DialogResult property to
Ok. Set the Cancel Button's DialogResult to cancel. You can do this in the
form designer.

Then, you can use this code:
prompt = new AddressPrompt();
// show the prompt modally, and check whether the user
// selected Ok or cancel:
DialogResult result = AddressPrompt.ShowDialog(this);
if(result == DialogResult.OK)
address[index] = prompt.addressInput;
else
// user cancelled the dialog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top