I'm working on a project that has two separate forms--one main form, and one secondary form. Both forms have controls and functions that the other forms needs to be able to read to and from. I'm struggling with how best to accomplish this. The way I've got it set up now:
Main form: frmMain
Secondary form: frmSecondaryCode:namespace nsSpace { public partial class frmMain : Form { frmSecondary frmTwo = new frmSecondary(); public frmMain() { InitializeComponent(); frmTwo.Show(); //Open secondary Form frmTwo.comboBox1.Items.Add("Item 1"); frmTwo.callSomeFunction(); } } }
The above code will open both forms, and frmMain seems to be able to make calls to frmSecondary just fine. The problem is making calls to frmMain FROM frmSecondary. Doing so produces the error: "An object reference is required for the nonstatic field, method, or property nsSpace.frmMain.callAnotherFunction()"Code:namespace nsSpace { public partial class frmSecondary : Form { public frmSecondary() { InitializeComponent(); frmMain.callAnotherFunction(); frmMain.comboBox5.Items.Add("Item 3"); } } }
I've tried declaring some things as static, but it just seems to make more things go wrong. Any help would be awesome.




Reply With Quote