I have 2 forms: Form1 and Form2. I opened Form2 using:
Form2 newForm2 = new Form2(this);
And now I want to access some variables or methods from Form1 that are set in public like: public int counter;
But when I try this from Form2 it gives me an error:
Error 4 'System.Windows.Forms.Form' does not contain a definition for 'StartGame' and no extension method 'StartGame' accepting a first argument of type 'System.Windows.Forms.Form' could be found (are you missing a using directive or an assembly reference?)
Edit:
In form 1:
Form2 newForm2 = new Form2(answer, button3, button4, button5, button6, this, fiftyfifty, web, change);
newForm2.Show();
In form 2:
Form originalParent;
public Form2(int answer, Button button3, Button button4, Button button5, Button button6, Form parentform, int fiftyfifty, int web, int change)
{
InitializeComponent();
originalParent = parentform;
}
and I’m trying to access this like originalParent."public Method here" and it gives me that error.
Your
Form2constructor is defined to get a genericFormas parameter in the constructor.You need to get a form of type
Form1, so change yourForm2constructor to: