L
L
littleguga2015-02-04 21:28:07
Programming
littleguga, 2015-02-04 21:28:07

How to stop code execution and continue it after certain conditions?

Good day to all!
There is form1 - some code is executed in it, then form2 is called, in it the user enters data and presses the button. How to continue executing code in form one after clicking a button in form2?

Form2 f = new Form2();
f.Show();
//Пользователь вводит данные в форме2
//Нажимает кнопку
doSomething();
MessageBox.Show("done");

So far, it only comes to mind - to drive into a cycle, for example
Form2 f = new Form2();
f.Show();
while(isDataWritten){
//а при нажатии на кнопку в форме2 - изменить значение isDataWritten на false
}
doSomething();
MessageBox.Show("done");

But premonition says it's the wrong way.
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oxoron, 2015-02-04
@littleguga

Make the OnConcreteButtonPressed event in form2. In the first, set up a handler (in your case, doSomething), create a second form, subscribe to the event, open the second form.
Form1 will have code like

Form2 f = new Form2();
f.OnConcreteButtonPressed += doSomething;
f.Show(); // лучше f.ShowDialog();

MessageBox() in doSomething().
In the second form, when the button is clicked, generate the OnConcreteButtonPressed event.

V
Vitaly Pukhov, 2015-02-05
@Neuroware

Judging by the context of the task, I recommend Google C# InputBox, there are various implementations of just such a task, that is, displaying a window for entering any data into it.

A
Andrey Golubkov, 2015-02-05
@Android97

And if the code is divided into 2 parts, and the execution is continued by pressing the button, it is permissible

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question