Event handling between forms
I am writing a C# game which consists of a number of forms which pass information between each other. I am having trouble creating an event handler that will enable form1 to do something once form2, which form1 has created, has performed a task.
form2 consists of a text box in which the user inputs an integar number, and I want to get it and store it as form1's x variable. There is an "OK" button on form2, which I want to use to send this value back to form1, and then close form2. Only once I have stored this value into x do I then want to perform function y.
public class form1 : form
Forms.Button button = new Forms.Button();
private void button_Click(object sender, EventArgs e)
myForm2 = new form2();
//Perform function y;
I have tried newbie things like while loops, to wait until form2 is closing and then read its value from the text box, but this kind of crashes it. I have also triend sending form1 as an argument when it creates form2, so that x can be set directly from form2. However, this way, function y will be called before the user has had time to put in the value into the text box, which is no acceptable.
So I need to do some sort of event handling here, so that form1 will wait until form2 has had its OK button pressed, and then form1 can perform function y. But I am a little unsure as to what exactly this would require...can anybody help?