Answer the question
In order to leave comments, you need to log in
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");
Form2 f = new Form2();
f.Show();
while(isDataWritten){
//а при нажатии на кнопку в форме2 - изменить значение isDataWritten на false
}
doSomething();
MessageBox.Show("done");
Answer the question
In order to leave comments, you need to log in
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();
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.
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 questionAsk a Question
731 491 924 answers to any question