public partial class Form2 : Form
{
private Form1 old_form;
public Form2(Form1 F)
{
...
old_form = F;
}
...
}
I change the given Form1 component (e.g. textBox) modifier to public and by this code I am able to change this object properties directly from Form2:old_form.textBox1.Text = "Bla";My first question is how it is possible? I don't understand why it works. As far as I know the old_form in Form2 is a new created object, which is only initialized by the argument F. And F is just a copy of the main Form1 object, so why changing its properties change in fact the first Form1? For me such behaviour seems like a reference, but there is no ref keyword in the constructor. Anyone could explain it to me?
My second question is if there is any other solution to solve this problem? To change Form1 components properties directly from the Form2? Because I think that described above solution is not quite "nice".
Thank You for help!


Sign In
Create Account

Back to top









