That means the functions that are opening the new forms are static methods
of the main form instead of instance methods. Is this on purpose, and, if
so, is there a reason they need to be this way?
Regardless, here's a pretty simple way of doing this. In you main form,
create a public static variable and use it for the call to
Application.Run(), e.g.
class MainForm : System.Windows.Forms.Form
{
public static MainForm TheMainForm = null;
public static void Main()
{
TheMainForm = new MainForm();
Application.Run(TheMainForm);
}
}
Now in any other form, if you need to reference the main form, do this:
class SomeOtherForm : System.Windows.Forms.Form
{
public SomeMethod()
{
string s = MainForm.TheMainForm.GetValueOfSomeTextBox();
}
}
Ken
Ray Stevens said:
Passing a reference to the main form does not work. The compiler give an
error "can't reference 'this'". I still can not find the instance variable
for the main form.