commuicating between 2 forms

  • Thread starter Thread starter Guest
  • Start date Start date
Hi,

Normally you keep a reference to one of the forms in the other form.
 
private void MyMethod()
{
OtherForm frm = new frmOtherForm;
frm.Show();
frm.SomeMethod();
}

or better using events..

private void MyMethod()
{
OtherForm frm = new frmOtherForm;
frm.Show();

if(signalEvent != null)
signalEvent(this, EventArgs.Empty);
}
 
To call a method you need to have a reference to the form. Once you have the
reference just call the method.

For example if form1 wants to call a method of form2, when you create the
forms create first form2 and them pass the reference when creating form1.
You can use constructor overload for example.
 
Create an instance of the other form and call a method.
Though if this method has nothing to do with UI, I would recommend putting
in a seperate class (not a form) and call from the class instance.
 
Back
Top