I want to pass some variables from the child form to the parent form.
So at the Main form or Parent form I added the variables as a constructor:
private SampleFunction()
{
int a, b;
//Here is where I want to use the x,y and z from the Second Form...
a = this._x*this._y;
b = this._y*this._z;
}
public MainForm(int x, int y, int z)
{ InitializeComponent();
this._x = x;
this._y = y;
this._z = z;
}
private void LoadVar_Click(object sender, EventArgs e)
{
ScndForm SecForm = new ScndForm();
SecForm.ShowDialog();
SecForm.Update();
}
Now my question is from the Form2 or Child form how to pass the variables?
public partial class ScndForm : Form
{
public ScndForm()
{
InitializeComponent();
}
MainForm Parent = new MainForm( x, y, z) //This Point
// Put them global?
int x, y, z;
public void OKButton_Click(object sender, EventArgs e)
{
x = this.xtxtbox.Text;
y = this.ytxtbox.Text;
z = this.ztxtbox.Text;
}
}
This is just a sample, not the complete code. But where is the comment //This point is giving to me an error saying: 'A field initializer cannot reference the non-static field, method or property'. What I am doing wrong?