WinForms- Modal forms that call functions which change original fo

G

Guest

I have a form with a button.

public class FrmMain : System.Windows.Forms.Form
{
....
public ProgramPreferences myAppPreferences;
....
}

The button opens up a new modal form:


private void btn_CLick(object sender, System.EventArgs e)
{

myApp.Form2 newForm= new Form2();
eventForm.ShowDialog();
eventForm.Focus();
}

From the new form, I'd like be able to call a frmMain function that redraws
the original form. How can I do this? I'm not sure how to refer to the
original object that instantiated the current object I'm in. I tried using
passing the object as an argument in the constructor, but the methods I've
created don't show (all are declared public) Any thoughts?

Thanks very much!
 
W

W.G. Ryan eMVP

Patrick:

If you pass in the form for instance, it should be showing up - do you have
a property in the second form that's being set so you don't have any scope
issues and/or have you verified the type of the first form parameter
argument? My other guess if niether of these is the problem is that perhaps
you have a different namespace on the first form - but that would give you a
compile error so that's probably not it either
 
B

Baavgai

Create a delegate (event) in Form2 that will signal FrmMain that it's
time to call a method. Call it something like this:

myApp.Form2 newForm= new Form2();
newForm += new EventHandler(callingForm2);
eventForm.ShowDialog();
....
void callingForm2(object sender, EventArgs e) {
....
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top