Results 1 to 6 of 6

Thread: Multiple Forms - passing calls to and from

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    13

    Thumbs up Multiple Forms - passing calls to and from

    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
    Code:
    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();
            }
        }
    }
    Secondary form: frmSecondary
    Code:
    namespace nsSpace
    {
        public partial class frmSecondary : Form
        {
            public frmSecondary()
            {
                InitializeComponent();
                frmMain.callAnotherFunction();
                frmMain.comboBox5.Items.Add("Item 3");
            }
        }
    }
    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()"

    I've tried declaring some things as static, but it just seems to make more things go wrong. Any help would be awesome.
    Last edited by Fedge; Aug 7th, 2007 at 02:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width