There is a Windows Form application for example say 'A'.

and there is another class called 'example.cs' that will call 'A' as apart of its action.

When 'example.cs' calls 'A' , 'A' will pop out, and continue to execute.

what i want to do is, when 'example.cs' calls 'A' , the example.cs code should stop continuing execution until the windows form 'A' is closed.

Hope yourl undestood my question. Basically, i need a form to popup (the form contains a button and a text box), so the user is required to enter some value to the text box and click on the submit button, and then only the example.cs code should continue executing its remaining code.

It is like Console.readline . where the execution of the codes remains still until someone types something in


Help appreciated.

When you make a new 'A' and tell it to Show(), you should see another method called ShowDialog(). This is exactly what you want as execution will not continue until that dialog is closed.

Here's an example. Assuming the form you want to call is named SubmitForm.

SubmitForm A = new SubmitForm();
A.ShowDialog();
MessageBox.Show("The submit form closed."); //This will not show until the form closes.

If you want the Submmit button to actually close the form. Then put this at the end of your code for it.

this.DialogResult = DialogResult.OK;

All forms shown as 'dialogs' return a DialogResult to the caller. They will close once their DialogResult has been assigned, which is what that code does. You can get its DialogResult by changing line 2 of the above to:

DialogResult SubmitResult = A.ShowDialog();

Now you'd just have to check the value with an IF statement. You don't have to do that though. ;)

Using your example, it would be

A myForm = new A();
A.ShowDialog();  // execution stops here until the user closes the form 'A'
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.