I have a quick question. I created a class in the Form2 called “MyObject” which has two variables in it. On the push of a button, the variables in Form2 are changed. Now my question is how to retrieve MyObject in Form1? Here is my sample code:
Form1
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2(this);
f.ShowDialog();
??????? (how can I retrieve Myobject here?????)
}
Form2
public class MyObject
{
public int Value1 { get; set; }
public int Value2 { get; set; }
}
public Form2(Form1 frm1)
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MyObject obj = new MyObject();
obj.Value1 = 102;
obj.Value2 = 50;
}
Thanks everyone
Do this
Form1
Form2
MyObject