I have three forms: Form1, Form2 and Form3. I want to be able to pass a reference to either Form2 or Form3 so that Form1 will invoke the appropriate one when a button is clicked. So I set up a Form property in Form1:
I've passed other object references in this manner (specifically, an OdbcConnection), so I figured this would be fine.Code:private System.Windows.Forms.Form m_frmAddEdit;
...
public System.Windows.Forms.Form AddEditForm
{
get { return m_frmAddEdit; }
set { m_frmAddEdit = value; }
}
Unfortunately, when I try to pass a Form reference:
The compiler complains that:Code:Form1 frm = new Form1();
frm.AddEditForm = Form2;
andQuote:
'Form2' denotes a 'class' where a 'variable' was expected
This latter error is in reference to the following line in Form1:Quote:
'Form1.m_frmAddEdit' denotes a 'field' where a 'class' was expected
What am I doing wrong here? I don't understand why C# expects the property I declared as a Form to be a 'variable'.Code:m_frmAddEdit frmToCall = new m_frmAddEdit();
Do I need to be looking at some way to do this with Delegates instead? (I'd like to keep the calling/invoking logic inside Form1.)
