Reputation: 1567
I have 2 forms. One is the display form and the other is the where data is added to an array.
How do I start a function on the display form once the ok button has been clicked on the add to array form?
EDIT:
Let me rephrase. How would I go about calling a function that is in one .cs file, from another .cs file.
Form 1
private void menuItem1_Click(object sender, EventArgs e)
{
Form2 form2= new Form2();
form2.Owner = this;
form2.ShowDialog(this);
}
Form 2
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.myMethod();
}
Obviously, the form2 code is generating a new instance of form1.
How do I run the method of the form that opened the modal window?
Thanks
Upvotes: 0
Views: 2316
Reputation: 6281
The owner of Form2
is a instance of Form1
so you can cast the owner to Form1
and call the method:
(this.Owner as Form1).myMethod();
Upvotes: 2